Jump to content


Photo

Can't see whats wrong with my code


  • Please log in to reply
4 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 05 March 2006 - 07:29 PM

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 "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." 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.

#2 JasperBosch

JasperBosch
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationApeldoorn, The Netherlands

Posted 05 March 2006 - 07:39 PM

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.

#3 Sasuun

Sasuun
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 March 2006 - 08:00 PM

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
$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));

I know it doesn't seem like much of a change, but it's worked for me before

#4 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 05 March 2006 - 11:00 PM

Thanks it didnt seem like much but it did work

#5 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 06 March 2006 - 02:15 PM

Try this :

$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));

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.
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users