Jump to content

Archived

This topic is now archived and is closed to further replies.

OriginalSunny

Can't see whats wrong with my code

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.

Share this post


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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.