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:
PHP Code:
<!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’s Contacts Database ~ Record Updated</title>
</head>
<body>
<h1>Amir’s Contacts Database</h1>
<h2>Record Updated</h2>
<?
$id=$_POST['id'];
Need to move the die() to the mysql_query() statement:
PHP Code:
$query="DELETE FROM contacts WHERE id='$id'";
$result = @mysql_query($query) or die("Query Failed; $query - " . mysql_error());
// it worked, so let's see what really happened:
$numRows = mysql_affected_rows();
echo "<p>$numRows rows were deleted from the database.</p>\n";
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Okay, it's gonna sound crazy, but I didn't realise I needed to, cos I didn't need it to update a record.
It's passed to the 'delete' page like this:
PHP Code:
<? echo '<a href="delete.php?id='.$id.'">d</a>'?>
Try this:
PHP Code:
$query="DELETE FROM contacts WHERE id='{$_GET['id']}'";
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Need to move the die() to the mysql_query() statement:
PHP Code:
$query="DELETE FROM contacts WHERE id='$id'";
$result = @mysql_query($query) or die("Query Failed; $query - " . mysql_error());
// it worked, so let's see what really happened:
$numRows = mysql_affected_rows();
echo "<p>$numRows rows were deleted from the database.</p>\n";
I tried this, but saw no difference. The code I now have is:
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="DELETE FROM contacts WHERE id='$id'";
$result = @mysql_query($query) or die("Query Failed; $query - " . mysql_error());
// it worked, so let's see what really happened:
$numRows = mysql_affected_rows();
echo "<p>$numRows rows were deleted from the database.</p>\n";
mysql_close();
?>
Do the change of $id to {$_GET['id']} and I'll place a decent wager that it works.
EDIT: I just noticed you're setting $id = $_POST['id'], so try changing that to $_GET['id'].
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Need to move the die() to the mysql_query() statement:
PHP Code:
$query="DELETE FROM contacts WHERE id='$id'";
$result = @mysql_query($query) or die("Query Failed; $query - " . mysql_error());
// it worked, so let's see what really happened:
$numRows = mysql_affected_rows();
echo "<p>$numRows rows were deleted from the database.</p>\n";
That's what happens when I type with my eyes shut. Sorry about that.
Bookmarks