views:

63

answers:

3
+1  Q: 

MySQL INSERT Query

I have problem 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!

+7  A: 

'order' is a reserved word. You'll need to wrap it in backticks, but you'll have less headaches if you rename the column.

Joe
+5  A: 

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.

duffymo
+4  A: 

8 rows, 9 query parameters - you have a duplicate $email variable in the VALUES portion of the INSERT statement.

Steve B.