|
General Clean Up resets the |
Person Table |
Book Table |
Documentation |
||
|
Note - Create, Drop and Clean Up would be
hidden on a real life system. |
|||||
SELECT * FROM person ORDER BY last_name, first_name
Code Listing : personDelete.php |
<?php
require "../MySQL_Login.php"; // Contains host, username, password, and database
$link = mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db ($database) or die(mysql_error());
// ========================================================================
// This loop visits each item in the $_POST array.
// The array items are not numbered. They are named instead.
// This is called an associative array.
// The names of the array items are stored into $key.
// The item stored in the named position is copied into $value.
// If $key is not "Submit" then $value will contain a primary key value.
// This information was posted when the form on this page was submitted.
// ========================================================================
foreach ($_POST as $key => $value)
{
if ($key != "Submit")
{
$sql = "DELETE FROM person WHERE person_id = \"$value\"";
mysql_query($sql, $link);
$allSqls[] = $sql; // Add the SQL statement to an array of them.
}
}
// ========================================================================
$sql = "SELECT * FROM person ORDER BY last_name, first_name";
$allSqls[] = $sql; // Add the SQL statement to an array of them.
$result = mysql_query($sql, $link) or die(mysql_error());
mysql_close($link);
?>
<html>
<head>
<title>Delete a Person</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include "nav.php";
for ($ii = 0; $ii < count($allSqls); $ii++)
{
echo "<font size=\"+2\"><b><pre>" . $allSqls[$ii] . "</pre></b></font>\n";
}
?>
<form name="form1" method="post" action="personDelete.php">
<table border="1" cellspacing="0" cellpadding="4">
<tr>
<td><h3>ID</h3></td>
<td><h3>Title</h3></td>
<td><h3>First Name</h3></td>
<td><h3>Last Name</h3></td>
<td><h3>DOB</h3></td>
</tr>
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo " <tr>\n";
echo " <td>" . $row['person_id'] . "<input name=\"" .
$row['person_id'] . "\" type=\"checkbox\" id=\"" .
$row['person_id'] . "\" value=\"" . $row['person_id'] .
"\"></td>\n";
echo " <td>" . $row['title'] . "</td>\n";
echo " <td>" . $row['first_name'] . "</td>\n";
echo " <td>" . $row['last_name'] . "</td>\n";
echo " <td>" . $row['date_of_birth'] . "</td>\n";
echo " </tr>\n";
}
?>
<tr>
<td colspan="5" align="right"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
<?php
include "dump.php";
dump_page(basename($_SERVER[SCRIPT_FILENAME])); // Display the code of this page
?>
</body>
</html>
|