插入表时如何纠正语法错误?
"Insert Into " . $tableName . " (location_address) Values ('$location_address')"
在此代码中,当变量的值具有法语字符(例如
'
)时,出现错误,我无法修复。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')
谁能帮我?谢谢
最佳答案
在查询中插入变量之前,应转引号:
$location_address = addslashes($location_address);
您将获得以下字符串: