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.

4
  • you cant use multiple queries in one mysql_query() function call Commented Jan 27, 2015 at 19:26
  • you can't even use mysql_query))) Commented Jan 27, 2015 at 19:31
  • = = will also give you an error. Commented Jan 27, 2015 at 19:36
  • possible duplicate > question 2708237 Commented Jan 27, 2015 at 19:38

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Why can't he use multi query, supported by mysqlnd for example?
@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?
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.

2 Comments

This still does not work only the move is done the deletion of the record does not happen.
simple mistake...you are using double equals..(= = ) ..it should be single =. corrected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.