I have this code which is supposed to be deleting entry from a table…can’t seem to figure out what is wrong with it when run in browser nothing happens! :mad:
include('includes/dbConnect.inc.php');
// create database connection
$conn = dbConnect('admin');
// initialize flag
$deleted = false;
// get details of selected record
if ($_GET && !$_POST) {
// check that primary key is numeric
if (isset($_GET['schoolId']) && is_numeric($_GET['schoolId'])) {
$schoolId = $_GET['schoolId'];
}
else {
$schoolId = NULL;
}
if ($schoolId) {
$sql = "SELECT * FROM schools WHERE schoolId = $schoolId";
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_assoc($result);
}
}
// if confirm deletion button has been clicked, delete record
if (array_key_exists('delete', $_POST)) {
if (!is_numeric($_POST['schoolId'])) {
die('Invalid request');
}
$sql = "DELETE FROM schools
WHERE schoolId = {$_POST['schoolId']}";
$deleted = mysql_query($sql) or die(mysql_error());
}
// redirect the page if deletion successful, cancel button clicked, or $_GET['schoolId'] not defined
if ($deleted || array_key_exists('cancel_delete', $_POST) || !isset($_GET['schoolId'])) {
header('Location: schools_list.php');
exit;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
</head>
<body>
<div id="bodycontent" >
<h2>Delete school entry </h2>
if (!isset($schoolId) || empty($row)) {
<p class="warning">Invalid request: record does not exist.</p>
}
else {
<p class="warning">Please confirm that you want to delete the following item. This action cannot be undone.</p>
<p> echo htmlentities($row['schoolREgNo']).': '.htmlentities($row['schoolName']); </p>
}
<form id="delete" name="delete" method="post" action="" class="details">
<p>
if (!empty($row)) {
<input type="submit" name="delete" value="Confirm deletion" />
}
<input name="cancel_delete" type="submit" id="cancel_delete" value="Cancel" />
if (!empty($row)) {
<input name="schoolId" type="hidden" value=" echo htmlentities($row['schoolId']);" />
}
</p>
</form>
</div><!--end body contents div-->
</body></html>