Aditya Dev Aditya Dev - 5 months ago 11
SQL Question

Deleting SQL record using PHP

I am a beginner in PHP and SQL. I have been trying to delete rows in SQL table using the following code but it doesn't work. Please help.

<?php
/*
DELETE.PHP
Deletes a specific entry from the 'db' table
*/

// connect to the database
include('connect-db.php');

// check if the 'id' variable is set in URL, and check that it is valid

// get id value
$id = $_GET['id'];

// delete the entry
$result = mysql_query("DELETE FROM db WHERE 'Report No.'= '$id'")
or die(mysql_error());

// redirect back to the view page
header("Location: view.php");

// if id isn't set, or isn't valid, redirect back to view page
{
header("Location: view.php");
}

?>

Answer

Apply backticks(`) around table field name "Report No." (its not standard way to define a table field name)

Try this

$result = mysql_query("DELETE FROM db WHERE `Report No.`= '$id'");