我试图将一个字段从一个表移动到另一个表,然后将其从第一个表中删除。我遇到的问题是,它可以很好地移动数据,但不能从第一张表中删除它。
这是我的代码:
"INSERT INTO out_tickets SELECT * FROM tickets";
"DELETE FROM tickets WHERE * FROM tickets";
不确定我在做什么错吗?
编辑
更新代码:
<?php
// Process delete operation after confirmation
if(isset($_POST["id"]) && !empty($_POST["id"])){
// Include config file
require_once 'config.php';
// Prepare a select statement
$sql = "INSERT INTO out_tickets SELECT * FROM tickets";
"DELETE FROM tickets";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_id);
// Set parameters
$param_id = trim($_POST["id"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records deleted successfully. Redirect to landing page
header("location: technical.php");
exit();
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
答案 0 :(得分:0)
据我了解,您尝试将 ALL 列从一个表(t1)移至结构相同的另一个表(t2)(或移至包含第一个相同列的表),是否要从已移至t2的table1中删除数据? 如果正确,请使用下一个SQL
INSERT INTO t2 SELECT * FROM t1;
DELETE FROM t1 WHERE 1;