Aditya Dev Aditya Dev - 2 years ago 74
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");


Answer Source

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'");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download