erol_smsr erol_smsr - 2 months ago 10
MySQL Question

Unknown SQL syntax error PHP PDO

I have this code:

try {

$sql = "INSERT INTO order(
user_id,
departure_street,
departure_housenr,
departure_postalcode,
departure_city,
arrival_street,
arrival_housenr,
arrival_postalcode,
arrival_city,
order_date,
lifter,
order_status
)
VALUES(
:user_id,
:departure_street,
:departure_housenr,
:departure_postalcode,
:departure_city,
:arrival_street,
:arrival_housenr,
:arrival_postalcode,
:arrival_city,
:order_date,
:lifter,
:order_status
)";

$stmt = $dbh -> get_instance() -> prepare( $sql );

$stmt -> execute( array( ':user_id' => $_SESSION[ 'user_id' ],
':departure_street' => $street1_parsed,
':departure_housenr' => $streetnumber1,
':departure_postalcode' => $postcode1,
':departure_city' => $city1_parsed,
':arrival_street' => $street2_parsed,
':arrival_housenr' => $streetnumber2,
':arrival_postalcode' => $postcode2,
':arrival_city' => $city1_parsed,
':order_date' => $datetime,
':lifter' => $lifter,
':order_status' => $order_status ) );

}
catch( PDOException $e ) {

echo $e -> getMessage() . '<br />' . $sql;

}


This code keeps giving me this error:


SQLSTATE[42000]: Syntax error or access violation: 1064 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(
user_id,
departure_street, ' at line 1


I don't understand what can be wrong with the syntax. I've used this query so many times and it always works. What's the problem now? I've tried to
echo
the
$sql
variable to see what the resulting query looks like, but it doesn't show me the values that are being inserted. Can anyone see the SQL syntax error?

Answer

ORDER is mysql key word .it should be enclosed by backticks .if your table name or column name is key word just use backticks order backticks ``

here you can find the mysql keywords list

Comments