I have a page called delete.php that can be used to delete any records passed to it. Once the records are deleted I want the page to print a link back to the page that the user came from originally. The problem is that running the delete sql command clears out the page's data so that the "return link" becomes non-functional. How can this be avoided? Here is the code
#Choosing the correct database/establishing connection
$connection = mysql_connect("localhost", "xxxxxx", "xxxxxx") or die("Death!");
$pickdatabase = mysql_select_db("xxxx", $connection)
or die("Database Connection Problem!");
$delid = $_GET['delid'];
$dbtable = $_GET['dbtable'];
$idfield = $_GET['idfield'];
$origin = $_GET['origin'];
$deleteform="<form align=\"Center\" action=\"$PHP_SELF\" method=\"post\">";
$deleteform.="<p>Are You Sure You Want To Delete This Record?</p>";
$deleteform.="<a href=\"$origin\">Back</a>";
$deleteform.="<input type=\"hidden\" name=dbtable value=\"$dbtable\"></input>";
$deleteform.="<input type=\"hidden\" name=delid value=\"$delid\"></input>";
$deleteform.="<input type=\"hidden\" name=idfield value=\"$idfield\"></input>";
$deleteform.="<input type=\"submit\" name=\"cdelete\" value=\"Confirm Delete\" ></input>";
$deleteform.="</form>";
$cdelete = $_POST["cdelete"];
if($cdelete){
$delid = $_POST['delid'];
$dbtable = $_POST['dbtable'];
$idfield = $_POST['idfield'];
$origin = $_POST['origin'];
$delquery = "delete from $dbtable where $idfield='$delid'";
$rundelquery = mysql_query($delquery, $connection) or die("The Query failed");
echo("Record Deleted");
$origin = $_POST['origin'];
echo("<a href=\"$origin\">Back</a>");
}
else{
echo($deleteform);
}
?>