PDA

View Full Version : deleting a record from a database


Colm Osiris
02-13-2006, 04:02 PM
My database is coming on leaps and bounds. Now I'm trying to delete a record from it, but what seems to be happening is the record is being blanked, but not deleted. This is the script I have:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Taco HTML Edit">
<link rel="stylesheet" href="styles.css" type="text/css">
<title>Amir&rsquo;s Contacts Database ~ Record Updated</title>
</head>
<body>
<h1>Amir&rsquo;s Contacts Database</h1>
<h2>Record Updated</h2>
<?
$id=$_POST['id'];

$user="user";
$password="password";
$database="database";

mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="DELETE FROM contacts WHERE id='$id'";
mysql_query($query);
mysql_close();
?>
<br>
<a href="list.php">list</a>
</body>
</html>

:confused:

Kid Charming
02-13-2006, 05:33 PM
I'm not sure what you mean by 'blanked'.

Colm Osiris
02-13-2006, 05:36 PM
What I mean is the record still exists, but all its fields, apart from the id, are empty.

Kid Charming
02-13-2006, 05:51 PM
What does the form look like that leads to this page?

Colm Osiris
02-13-2006, 07:56 PM
The problem was that I had POST on the page with the 'delete' button on it, and GET on the result page. I swapped them round, and it works perfectly.

Thank you for your time :-)