简体   繁体   English

如何在MySQL中移动然后删除字段

[英]How to move then delete field in MySQL

I am trying to move a field from one table to another and then delete it from the first table. 我试图将一个字段从一个表移动到另一个表,然后将其从第一个表中删除。 The problem I am having is that it moves the data fine, but it is not deleting it from the first table. 我遇到的问题是,它可以很好地移动数据,但不能从第一个表中删除它。

Here is my code: 这是我的代码:

"INSERT INTO out_tickets SELECT * FROM tickets";
        "DELETE FROM tickets WHERE * FROM tickets";

Not sure what I am doing wrong? 不确定我在做什么错吗?

EDIT 编辑

Updated Code: 更新的代码:

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

As I understand you trying to move ALL columns from one table (t1) to another table (t2) with same structure (or to table, that contain same columns like in first) and than you want to delete data from table1 that you moved to t2? 据我了解,您试图将所有列从一个表(t1)移至具有相同结构的另一个表(t2)(或移至包含第一个相同列的表),然后又想从移至的表1中删除数据T2? If correct use next SQL 如果正确使用下一个SQL

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

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

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