0
 $con = mysql_connect($server, $user, $password);
     if (!$con)
     {
     die('Could not connect: ' . mysql_error());
     }
     mysql_select_db($user, $con);
     $ref='444';
    $name="x7";
$quant =1;
    $price=7000;
    $sql=  "INSERT INTO order(ref_id, name, quantity, price, status) VALUES      ('$ref','$name','$quant','$price','pending')"; 
    if (!mysql_query($sql,$con))
     {
     die('Error: ' . mysql_error());
     }

This code is in php block. when i execute it i get this:

Error: 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 'order(ref_id, name, quantity, price, status) VALUES ('444','x7','1','7000','pend' at line 1

So any idea where i am going wrong? When I read the content of the table, it works fine thus proving that the connection and db is working fine. I am getting this problem whenever I try to populate a table. I am a Newbie in php and mysql :(. Please excuse me if the code contain a very silly mistake of mine :)

2
  • Hello, my name is using reserved MySQL words and it shot me in the foot. Commented Nov 24, 2011 at 15:00
  • i solved it :D thanks guys. i changed the name of the table for good and its working normally. thanks again :D Commented Nov 24, 2011 at 15:04

3 Answers 3

5

order is a mysql reserved word you have to surround it with backticks `` like this

$sql="INSERT INTO `order`(ref_id, name, quantity, price, status)...
Sign up to request clarification or add additional context in comments.

Comments

1

order is a reserved word in mysql. It needs to be escaped using back ticks.

See - http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Comments

0

Try:

INSERT INTO `order`(ref_id, name, quantity, price, status) VALUES      ('$ref','$name','$quant','$price','pending')

this also can help: How can I make a table in MySQL called "order"?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.