1

I am trying to move the records from table studentrecords to passivestudents but i am not being able to. so far i've tried.

<?php
    $db = new mysqli("localhost", "root", "","learndb");
    if ($db->connect_error) {
        die("Connection failed this is the error: " . $db->connect_error);
       }
    $id=$_GET['id'];
    $sql="INSERT INTO passivestudents VALUES (DELETE FROM studentrecords WHERE id=$id)";
    $result=$db->query($sql);
    if(!$result)
    {
        echo"ERROR MOVING";
    }
    else
    {
        echo "<center><p style=\"color:green\">Information Moved!</p></center>";
    }
    ?>
micky
  • 277
  • 1
  • 13
  • 39
  • This was answered in [this post](http://stackoverflow.com/questions/19821736/mysql-move-rows-from-one-table-to-another), moving from one table to another – Quinton Zinn Feb 07 '16 at 05:42
  • @QuintonZinn tried that. – micky Feb 07 '16 at 06:01
  • Reverse your queries sequence first insert in the second table and then delete from first one. – Lawakush Kurmi Feb 07 '16 at 07:01
  • You can't use where clause inside INSERT query. Try update instead of it. Also you query is wrong. You have to get the results before inserting it into another table. – Kvvaradha Feb 07 '16 at 08:22

1 Answers1

0

your query was wrong . you want to remove student with some id ? true ?

so follow these step:

1-INSERT INTO your_sec_table (select * from first_Table where id= $id;

2-DELETE FROM first_table WHERE id=$id

  • i've tried this $sql=`"INSERT INTO passivestudents (select* FROM studentrecords WHERE id=$id); DELETE FROM studentrecords WHERE id=$id"; $result=$db->query($sql);` but failed. – micky Feb 07 '16 at 05:59
  • `$sql1="INSERT INTO passivestudents (select* FROM studentrecords WHERE id=$id)"; $sql2="DELETE FROM studentrecords WHERE id=$id"; $db->query($sql1); $db->query($sql2);`@micky – Sanzeeb Aryal Feb 07 '16 at 06:37
  • do you have teamviewer software? –  Feb 07 '16 at 06:39
  • You must debug your code , to see which part have error! , maybe field doesn't match , or other reasons. –  Feb 07 '16 at 06:46