473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

SQL syntax error in delete statement

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where stock_id=19721' at line 1"

I have been banging my head trying to find out where is it, this error message will be display when that locater shows negative stock and Receive new stocks to that locater.

[PHP]
<?php
$q ="select stock_id,quantity from stock where item_id=$item_id and locator_id=$locator_id";
$result = mysql_query($q)or die(mysql_error()) ;
if(!$result || (mysql_numrows($result) < 1))
{

$q ="insert into stock (item_id,locator_id,quantity) values($item_id,$locator_id,$qty)";
mysql_query($q)or die(mysql_error()) ;
}
else
{

$row = mysql_fetch_row($result);
mysql_free_result($result);
$total=$qty+$row[1];
$q ="update stock set quantity=$total where stock_id=$row[0]";
mysql_query($q)or die(mysql_error()) ;
}
$q ="select stock_id,quantity from stock where item_id=$item_id and locator_id=$locator_id";
$result = mysql_query($q)or die(mysql_error()) ;
$row = mysql_fetch_row($result);
if($row[1]==0)
{
$q ="delete stock where stock_id=$row[0]";
mysql_query($q)or die(mysql_error()) ;
}


$q="insert into log (Log_Type_ID,item_id,Locator_ID,Quantity,Date_Time ,thrid_reference,User_ID) values(6,$item_id,$locator_id,$qty,sysdate(),'$Ref erence','$username')";
mysql_query($q)or die(mysql_error()) ;

$q = "update remotestatus set step=6 where ip='$ip'";
mysql_query($q)or die(mysql_error()) ;
?>
[/PHP]

Just wandering if someone has similar issue. please advise
Mar 3 '08 #1
3 1785
ronverdonk
4,258 Expert 4TB
No the correct delete syntax is 'delete from', ie.
Expand|Select|Wrap|Line Numbers
  1. ..delete from stock where stock_id=...
Ronald
Mar 3 '08 #2
No the correct delete syntax is 'delete from', ie.
Expand|Select|Wrap|Line Numbers
  1. ..delete from stock where stock_id=...
Ronald
Thank you for your help, problem solved. Sorry, my brain was not working today :P

Best Regards
Mar 4 '08 #3
ronverdonk
4,258 Expert 4TB
Thank you for your help, problem solved. Sorry, my brain was not working today :P

Best Regards
Happens to me frequently. See you again next time.

Ronald
Mar 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steve | last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone can explain to me why it was reported that way. ...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: Bob Stearns | last post by:
The statement: merge into nullid.animals_et_in t1 using is3.animals t2 on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and t1.sire_regnum=t2.regnum when matched then update set...
4
by: Robert | last post by:
What is the syntax to use in a VBA script to execute a pass-through? Thanx
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
0
by: compuglobalhypermeganetz0r | last post by:
I am having trouble getting an adapter to update my access database, it gives the error Syntax error in INSERT INTO statement. for Line 98: Adapter.Update(WineDS, "tblWines") Below is my...
3
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
9
by: ProgrammerGal | last post by:
I am hoping this is a quick easy question for someone! :) I am trying (struggling) with moving data from Sql Server to a Lotus Notes table. I am using SQL Server 2000, I have a Lotus Notes...
16
by: Chuck | last post by:
Please help me correct the statements in sub "BoundData" The following sub is in a module. Everything runs with no error messages, however,data is not reaching the text box. Data is being...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.