Aditya Dev Aditya Dev - 4 months ago 7x
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.

Deletes a specific entry from the 'db' table

// connect to the database

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



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