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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?