【发布时间】:2016-02-07 05:39:09
【问题描述】:
我正在尝试将记录从表 studentrecords 移动到 passivestudents,但我无法做到。到目前为止我已经尝试过了。
<?php
$db = new mysqli("localhost", "root", "","learndb");
if ($db->connect_error) {
die("Connection failed this is the error: " . $db->connect_error);
}
$id=$_GET['id'];
$sql="INSERT INTO passivestudents VALUES (DELETE FROM studentrecords WHERE id=$id)";
$result=$db->query($sql);
if(!$result)
{
echo"ERROR MOVING";
}
else
{
echo "<center><p style=\"color:green\">Information Moved!</p></center>";
}
?>
【问题讨论】:
-
这已在this post 中得到回答,从一张桌子移动到另一张桌子
-
@QuintonZinn 试过了。
-
反转查询顺序,首先插入第二个表,然后从第一个表中删除。
-
您不能在 INSERT 查询中使用 where 子句。尝试更新而不是它。你的查询也是错误的。您必须在将结果插入另一个表之前获取结果。