dousi8237 2017-01-05 23:03
浏览 39
已采纳

从一个SQL表中删除并添加到另一个[重复]

This question already has an answer here:

I realize this is probably a simple execute problem, but I am stuck. I have the record DELETE just fine, but it does not show up in the second table.

 <?php
   if( $_SERVER['REQUEST_METHOD']=='GET' && isset( $_GET['job_numb'] ) ){
   $job_numb = filter_input( INPUT_GET, 'job_numb', FILTER_SANITIZE_STRING );
   }
 ?>

Note the server request from the URL above. This is how I passed my $job_numb. Now I am going to pick it back up in my SELECT query below:

 $servername = "localhost";
 $username = "ccccc";
 $password = "xxxxx";
 $dbname = "jobs_users";

     // Create connection
     $conn = mysqli_connect($servername, $username, $password, $dbname);

     // Check connection
     if (!$conn) {
          die("Connection failed: " . mysqli_connect_error());
     }

 $sql = "SELECT * FROM jobs_canjobs WHERE job_numb = $job_numb";
 $results = mysqli_query($conn, $sql);

 if ($row = mysqli_fetch_array($results)){
      $job_name = $row['job_name'];
      $comments = $row['comments'];
      $due_date = $row['due_date'];
      $show_date = $row['show_date'];
      $attachment1 = $row['attachment1'];
      $requestor = $row['requestor'];
      $status = $row['status'];
      $req_email = $row['req_email'];
      $Property = $row['Property'];
      $assignee = $row['assignee'];
      $assign_email = $row['assign_email'];
      $AE = $row['AE'];
 }else{
      echo 'no records found';
 }
      mysqli_close($conn);
?>

I could also put these results into an array and pick from each of them, but at the time of this writing this is how the code existed so I did not edit that part.

Now with all of these variables loaded from the MySQL that corresponds to the queried $job_numb, you can add them into a page for results.

</div>
  • 写回答

1条回答 默认 最新

  • douchu4048 2017-01-05 23:11
    关注

    Try

      $sql = "INSERT INTO `archived_jobs` SELECT * from `jobs_canjobs` where job_numb = $job_numb";
      $results = mysqli_query($conn, $sql);
      $sql = "DELETE FROM `jobs_canjobs` WHERE job_numb = $job_numb";
      $results = mysqli_query($conn, $sql);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 方程如何编到C语言!
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了