我试图从另一个表中的现有变量和选定列插入数据
这是我的代码
$jobtitle=$_POST['jobtitle'];
$jobdescription=$_POST['jobdescription'];
$requirements=$_POST['requirements'];
$resume=$_POST['resume'];
$expyears=$_POST['expyears'];
$submit=$_POST['submit'];
$useremail=$_SESSION['email'];
$insert=mysql_query("INSERT INTO career (jobtitle, jobdescription, requirements, expyears, resume, useremail, resname) VALUES ('$jobtitle','$jobdescription','$requirements','$expyears','$resume','$useremail', SELECT resname FROM restaurant WHERE useremail='$useremail')");
但上面的代码没有给我的数据库带来任何结果
这个问题有什么解决方案吗?
感谢
答案 0 :(得分:3)
Note that you shouldn't be using mysql_*
functions因为它是一个已弃用的库。考虑转移到mysqli_*
或PDO。
话虽如此,您的查询不正确。您无法在VALUES()
语句中同时使用INSERT
和选择。您应该选择要插入的字符串文字以及您要选择的一个值。
请尝试以下方法:
$query = "
INSERT INTO career (jobtitle, jobdescription, requirements, expyears, resume, useremail, resname)
SELECT '$jobtitle','$jobdescription','$requirements','$expyears','$resume','$useremail', resname
FROM restaurant
WHERE useremail='$useremail'
";