View Full Version : Deleting a record and updating another table

06-25-2010, 10:41 PM
Hi Chaps

I am a little stumped with the following.

My client has a big database of companies, there not IT savvy and I want to create a record of anything they delete as a sort of backup.

Code below which does the deletion.

if ($del){

$query =sprintf("DELETE FROM main where id='$del'");
mysql_query($query,$dbh)or die(mysql_error());


<td width="56"><div align="center">
<input name="delete" type="button" id="delete" onClick="document.location.href='update.php?del=<?php echo $row['id']?>'" value="Delete"/>

Would the following code do want I want in theory?

if ($del){

$query =sprintf("INSERT into backup where id='$del' (Registration_No,COMPANY,ADDRESS) VALUES
mysql_query($query,$dbh)or die(mysql_error());

$query =sprintf("DELETE FROM main where id='$del'");
mysql_query($query,$dbh)or die(mysql_error());


06-26-2010, 01:36 AM
not sure but i dont think so
what if you first save the info they delete as a string (via $_post) then you can do the 2 processes as the info exists in a string , then maybe
if ($del){
}end if.
i think that would work

06-27-2010, 08:13 AM
You should never delete anything in production

Use a visibility flag in your database to switch records on or off in your select statements

06-28-2010, 09:37 AM

Good point... infact I just realised the customer wants this after reading the brief. DOH!!!!

I then just have up date my query in the PHP select where active = "Y" for example... job done.