gpt4 book ai didi

php - 如何移动然后删除MySQL中的字段

转载 作者:行者123 更新时间:2023-11-29 17:12:45 24 4
gpt4 key购买 nike

我正在尝试将字段从一个表移动到另一个表,然后从第一个表中将其删除。我遇到的问题是它可以很好地移动数据,但不会从第一个表中删除它。

这是我的代码:

"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.";
}
}

最佳答案

据我了解,您试图将所有列从一个表(t1)移动到具有相同结构的另一个表(t2)(或移动到包含与第一个相同列的表),并且比您想要删除 table1 中移至 t2 的数据吗?如果正确则使用下一个 SQL

INSERT INTO t2 SELECT * FROM t1;
DELETE FROM t1 WHERE 1;

关于php - 如何移动然后删除MySQL中的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51807146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com