PHP mySQL using xamp Move data table to other table

<?php
$connect = mysqli_connect("localhost", "root", "", "root");
if(isset($_POST["id"]))
{
 foreach($_POST["id"] as $id)
 {
  $query = "INSERT INTO tbl_released (id, branch, outlet, user, item, serialno, dater, problem, status, remarks, tech)
  SELECT id, branch, outlet, user, item, serialno, dater, problem, status, remarks, tech
  FROM tbl_repair WHERE id = '".$id."'";
  mysqli_query($connect, $query);
 
 }
}
?>

that code copy data from tbl_repair to tbl_released. now What I want to happen is to copy data and remove it from source table which is tbl_repair. Something that I want to move the data.
i tried the code
<?php
$connect = mysqli_connect("localhost", "root", "", "root");
if(isset($_POST["id"]))
{
 foreach($_POST["id"] as $id)
 {
  $query = "INSERT INTO tbl_released (id, branch, outlet, user, item, serialno, dater, problem, status, remarks, tech)
  SELECT id, branch, outlet, user, item, serialno, dater, problem, status, remarks, tech
  FROM tbl_repair WHERE id = '".$id."' DELETE FROM tbl_repair";
  mysqli_query($connect, $query);
 
 }
}
?>
but the code is not working...can you help me guys how to solve my problem...
repmove.php
Yaku KakashiAsked:
Who is Participating?
 
kenfcampConnect With a Mentor Commented:
Well assuming that your copy code works,

{

$query = "INSERT INTO tbl_released (id, branch, outlet, user, item, serialno, dater, problem, status, remarks, tech)
SELECT id, branch, outlet, user, item, serialno, dater, problem, status, remarks, tech FROM tbl_repair WHERE id = '".$id."'";
mysqli_query($connect, $query);

$delquery = "delete from tbl_repair where id = '$id'";
mysqli_query($connect, $delquery);

}
1
 
kenfcampCommented:
First check your code for typo's and see if that resolves your issue

You've indicated two tables tbl-released and tbl-repair and your code references 3:  
tbl_released, tbl_repair, and tbl-repair

$query = "INSERT INTO tbl_released (id, branch, outlet, user, item, serialno, dater, problem, status, remarks, tech)
  SELECT id, branch, outlet, user, item, serialno, dater, problem, status, remarks, tech
  FROM tbl_repair WHERE id = '".$id."' DELETE FROM tbl-repair";

Ken
1
 
Yaku KakashiAuthor Commented:
Thanks Bro. Corrected. Can you help me to solve the issue?... Thanks in advance
0
 
Yaku KakashiAuthor Commented:
It works like a charm...Thank you so much...
0
 
kenfcampCommented:
You are welcome
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.