简体   繁体   English

语法错误:MySQL插入选择

[英]Syntax error:MySQL Insert Select

I have this query to insert into tbl_userprofile: 我有此查询要插入到tbl_userprofile中:

$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'";

I'm getting a syntax error saying: "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 'pet-peeve', 'dirt' FROM tbl_user WHERE username = 'alex'' at line 2" 我收到一个语法错误,说:“您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以获取正确的语法,以便在'pet-peeve','dirt'处使用from FROM tbl_user WHERE username =第2行的“ alex””

NOTE: pet-peeve and dirt are the question and answer. 注意:宠物怒气冲冲和肮脏是问题和答案。 I dont know how i'm getting a syntax error. 我不知道我怎么得到语法错误。 Please where is my syntax error? 请问我的语法错误在哪里? Thanks 谢谢

在最后两个字段中可能会有一些纯文本,因此可能会有引号,最好在$question$answer变量中使用addslashes()

'$email', '".addslashes($question)."', '".addslashes($answer)."' FROM tbl_user

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM