1

I searched a great deal for a solution to this problem, however i have had no luck in finding an answer, i am trying to archive a row from one table to another and then delete the row from the original table. I have the code set up how i think it should be but it only moves the record it does not delete it from the Original table.

mysql_connect('localhost', 'brokensky', 'password');
mysql_select_db('isad235database');

$select = filter_var($_POST['selectlist'],FILTER_SANITIZE_STRING);

$query = "INSERT INTO `serversarchive` (`Server_ID`,`Server_name` , `Location` , `MAC_Address` , `Port_Number` , `IP_Address`, `Operating_System`, `Administrator`, `Contact_Number`, `Email` , `Second_Contact`, `Second_Contact_Number`, `Comments`)
SELECT * FROM `servers`
WHERE `Server_ID` = '$select'; DELETE FROM server WHERE Server_ID = = '$select'";

As i have looked around for several hours with no decent answer to this, i think this could be useful to others also.

bSky
  • 187
  • 2
  • 12

2 Answers2

2

You need to do the steps in sequence. If they need to happen as an atomic unit, use a transaction.

See also: PHP + MySQL transactions examples

Community
  • 1
  • 1
PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56
  • Why can't he use multi query, supported by `mysqlnd` for example? – Daniel W. Jan 27 '15 at 20:17
  • @DanFromGermany `mysqlnd` is not well supported on budget-oriented hosts. Best to stick to the basics. Anyway, I'm not familiar with it -- perhaps you want to write an answer? – PaulProgrammer Jan 27 '15 at 22:14
0

You need to execute sequentially.

$query = "INSERT INTO `serversarchive` (`Server_ID`,`Server_name` , `Location` , `MAC_Address` , `Port_Number` , `IP_Address`, `Operating_System`, `Administrator`, `Contact_Number`, `Email` , `Second_Contact`, `Second_Contact_Number`, `Comments`)
SELECT * FROM `servers`
WHERE `Server_ID` = '$select'"; 

//execute first  

$query2 = "DELETE FROM server WHERE Server_ID = '$select'"; // == should be single =

//now execute this one.
Riad
  • 3,822
  • 5
  • 28
  • 39
  • This still does not work only the move is done the deletion of the record does not happen. – bSky Jan 27 '15 at 19:44
  • simple mistake...you are using double equals..`(= = )` ..it should be single =. corrected. – Riad Jan 28 '15 at 11:49