MySQL INSERT Query [closed]
I have probl开发者_如何学Pythonem with my MySQL query:
include '../inc/mysql_config.php';
$sql="INSERT INTO ordrar
(id, order, namn, adress, postnummer, postort, email, status)
VALUES
(NULL, '$order','$namn','$adress','$postnummer', '$postort', '$email', '$email', '$status')";
mysql_query($sql);
if (!mysql_query($sql)) { die('Error: ' . mysql_error()); }
This outputs:
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, namn, adress, postnummer, postort, email, status) VALUES ' at line 1
Thanks.
Solved:
include '../inc/mysql_config.php';
$sql="INSERT INTO ordrar (id, substans, namn, adress, postnummer, postort, email, status)
VALUES
(NULL, '$substans','$namn','$adress','$postnummer', '$postort', '$email', '$status')";
mysql_query($sql);
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
Thanks everyone!
'order' is a reserved word. You'll need to wrap it in backticks, but you'll have less headaches if you rename the column.
I count 8 column names and 9 values. Is '$email' meant to be repeated?
"ORDER" might be a keyword - from ORDER BY SQL. Maybe a quick column name change could fix it. Try it and see.
8 rows, 9 query parameters - you have a duplicate $email variable in the VALUES portion of the INSERT statement.
精彩评论