Using the following code:
if (isset($_POST['delete']) && isset($_POST['id']))
{
$first = get_post('first');
$query = "DELETE FROM user_master WHERE id='$id'";
if(!mysql_query($query, $db_server))
echo "DELETE failed: $query<br />" .
mysql_error() . "<br /><br />";
}
$query="SELECT * FROM user_master";
$result= mysql_query($query);
if(!result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);
for ($j=0 ; $j<$rows ; ++$j)
{
$row = mysql_fetch_row($result);
echo <<<_END
<pre>
ID $row[0]
First $row[1]
Last $row[2]
Email $row[3]
User $row[4]
</pre>
<form action="willingLog.html" method="post">
<input type="hidden" name="delete" value="yes" />
<input type="hidden" name="id" value="$row[0]" />
<input type="submit" value="DELETE RECORD" /></form>
_END;
I’m unable to delete a record form the table.
All the records form the table are printing on the screen, including the “DELETE RECORD” button. When I hit the button, however, nothing happens. I’ve checked the actual table on phpmyadmin, and the table is unaffected as well.
I’m pulling this stuff from a book, so I don’t understand why it’s not working.
I do not see where you set the
$idvariable.Please be sure to sanitize any data sent across the network, i.e.
$_POST. Also, ifidis of a number type, do not surround the value in quotes or mysql will interpret it as a string.Lastly, look into using MySqli or PDO, as MySql API has been deprecated.