OriginalSunny Posted March 5, 2006 Share Posted March 5, 2006 Hi, i can't seem to find anything wrong with this code i have used, however there seems to be an error with it. The error being reported is [i]"sql_item: 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 ' 1,)' at line 4."[/i] The code i have used is: $sql_item = "INSERT INTO Order_Item (orderID, quantity,price) VALUES ($orderID, $value,{$row['price']})"; $result = mysql_query($sql_item,$connect) or die("sql_item: ".mysql_error($connect));Can anyone see what i am doing wrong?? The other strange thing is that this code begins on line 50. Quote Link to comment Share on other sites More sharing options...
JasperBosch Posted March 5, 2006 Share Posted March 5, 2006 Hi,My first gues is to remove the { and } in your sqlstatement. I think they don't belong there.The linenumber in the errormessage is the linenumber within you sqlstatement, not your php-code. Quote Link to comment Share on other sites More sharing options...
Sasuun Posted March 5, 2006 Share Posted March 5, 2006 insert statements can be a real pain... my guess is mysql wants you to do something with how your values are stated, I would start by adding '' around all of the varues in the VALUES() part of your query. try this[code] $sql_item = "INSERT INTO Order_Item(orderID,quantity,price) VALUES('$orderID','$value','{$row['price']}')";$result = mysql_query($sql_item,$connect)or die("sql_item: ".mysql_error($connect));[/code]I know it doesn't seem like much of a change, but it's worked for me before Quote Link to comment Share on other sites More sharing options...
OriginalSunny Posted March 5, 2006 Author Share Posted March 5, 2006 Thanks it didnt seem like much but it did work Quote Link to comment Share on other sites More sharing options...
XenoPhage Posted March 6, 2006 Share Posted March 6, 2006 Try this :[code]$sql_item = sprintf('INSERT INTO Order_Item (orderID, quantity,price) VALUES (%d,%d,%f)', $orderID, $value, $row['price']);print "QUERY - $sql_item";$result = mysql_query($sql_item,$connect)or die("sql_item: ".mysql_error($connect));[/code]This assumes that the first 2 values are decimal values, and the last is a float. If not, you need to adjust accordingly. (%s for string, %f for float, etc)The print line above should display the query at it was built. That should give you an indication as to what the problem is. The most common problem with these is that one of the values is uninitialized and prints nothing. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.