I have a delete form wherein the user will enter the pnum to be deleted and then it will delete the corresponding record. But I want the user to atleast see what would be deleted so I tried this code, but it doesnt seem to work:
<?php
$con = mysql_connect("localhost","root","nitoryolai123$%^");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Hospital", $con);
$result = mysql_query("SELECT * FROM t2 WHERE PNUM='{$_POST["pnum"]}'");
?>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="DeletebyPnumIn.php" method="post" onSubmit="return confirm('Are you sure you want to delete "<?php echo $row["LASTNAME"]; ?>" )">
what might be the correct way of doing this?
The code above does not include a line like:
You will need that for $row[‘LASTNAME’] to be set.
Otherwise, it looks like your code should work. You don’t say how it doesn’t work though. And it’s hard to tell if this is the first page where they enter the pnum or a second page where the deletion is being confirmed. If it’s the first page, you won’t have the pnum to run the query on.
Instead of using javascript, you could have the original form post to a page that displays as much of the record information as you want to show the user. That page could have a simple “Are you sure…” form with buttons to delete or cancel.