What am I missing in this code!

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::confused:

 // 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');

<!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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />



	<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">
	 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']);" />
</div><!--end body contents div-->

I always understood that SQL should be like this:

select * from tablename where something=‘this’

You’re not using the ’ in your SQL in your where clause.

Can you please specify where exactly I should put ’ because I have two where statements and I have tried both still ain’t working

Eephw!..got it!:rofl:…It was the problem with the delete link in the schools_list. Thank you though;)


Look at my sql and then back at yours.

Yours appear to be integers so it doesn’t matter but had your variables been text you would need to surround them with a ’ at either side.