doudu8291 2018-08-12 08:37
浏览 79

如何在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.";
    }
}
  • 写回答

1条回答 默认 最新

  • drny60365 2018-08-12 08:49
    关注

    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? If correct use next SQL

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

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算