Jump to content

Can't see whats wrong with my code


OriginalSunny

Recommended Posts

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.