0
我有這個疑問插入到tbl_userprofile:語法錯誤:MySQL的插入選擇
$SQL = "INSERT INTO tbl_userprofile (userId, name, surname, gender, nationality, address, mobile, department, email, question, answer)
SELECT tbl_user.Id , '$name', '$surname', '$gender', '$nationality', '$address','$mobile', '$department', '$email', '$question', '$answer'
FROM tbl_user
WHERE username = '$uname'";
我得到一個語法錯誤,他說:「你在你的SQL語法錯誤;檢查符合手冊你的MySQL服務器版本的正確語法使用附近'pet-peeve','dirt'FROM tbl_user WHERE username ='alex''at line 2「
注意:pet-peeve和灰塵是問題和答案。 我不知道我是如何得到一個語法錯誤。請問我的語法錯誤在哪裏?由於
嘗試將代碼與顯式值的inser聲明有測試並從MySQL查詢客戶端運行它。 – gpicchiarelli
我看不出語法上的任何錯誤,除了語句被sql注入漏洞。在數據庫上執行它之前,您可以請回顯您的查詢嗎? –
在這兩個最後一個字段中可能會有一些純文本,所以也許會有引用,最好使用[addslashes()](http://php.net/manual/en/function.addslashes.php)到'$問題'和'$ answer'變量 – Fabio