<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Joke CMS: Delete Author</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$dbcnx = mysql_connect('localhost', 'root', 'mypassword');
if (!$dbcnx) {
exit('<p>Unable to connect to the database server at this time.</p>');
}
if (!@mysql_select_db('ijdb')) {
exit('<p>Unable to locate the joke database at this time.</p>');
}
// Delete all jokes belonging to the author along with the entry for the author.
$id = $_GET['id'];
$ok1 = @mysql_query("DELETE FROM joke WHERE authorid='$id'");
$ok2 = @mysql_query("DELETE FROM author WHERE id='$id'");
if ($ok1 and $ok2) {
echo '<p>Author deleted successfully!</p>';
} else {
echo '<p>Error deleting author from database!<br />' .
'Error: ' . mysql_error() . '</p>';
}
?>
<p><a href="authors.php">Return to authors list</a></p>
</body>
</html>
This is the original code in the book. The user clicks on a delete link from another page (authors.php), and the author is immediately deleted. I've been trying to use an if else statement to bring up a prompt which asks the user to confirm the deletion before the author's name is deleted.
Bookmarks