Reputation: 131
How to correct syntax error when inserting into a table?
"Insert Into " . $tableName . " (location_address) Values ('$location_address')"
In this code, when the value of the variable has French characters, such as '
, give an error, I cannot fix it.
Message: 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 'Université, Quebec City, QC, Canada')' at line 1, query was: Insert Into addresses_store_location (location_address) Values ('Université Laval, Pavillon Alphonse-Desjardins, Rue de l'Université, Quebec City, QC, Canada')
Who can help me? thanks
Upvotes: 1
Views: 645
Reputation: 852
Before insert your variable in query you should escape quotes:
$location_address = addslashes($location_address);
You will get the following string:
l\'Université
Upvotes: 2
Reputation: 85
Your error is due to your single quote at l'université
you can escape it with \'
Hope this can help
Upvotes: 0