Hello all. I am trying to put a checkbox at the end of each row in a list of results. When checked of course, the selected rows should be deleted based on a logged in $username and the $id.
The various problems I have had are three-fold:
List When I check the box and click the delete button, the row is removed BUT, in the database itself, I am always one row short of what is printed on the screen -- this to me means that the page needs to reselect from the database -- but when and where?;
(2) the action="<?=$_SERVER['PHP_SELF']?>" doesn't refresh the page properly -- see (1) I think it might be related; and
(3) when I use the refresh button in my browser, it deletes another row even though nothing was checked - database looses another entry as does the page (same problem as (1) I suppose).[/List]Here is my code snippet after database connections, sessions etc are set:
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<?php
print "<table border=0 cellspacing=1 cellpadding=3 width=600>
<tr valign=top>
<td width=320><a href=http://www.mysite.com/page.php?id=$id target=_blank>$title</a>$pixel</td>
<td width=88>$cat2 Entry</td>
<td width=130>$ends</td>
<td width=70>
<div align=center>
<input type='checkbox' name='id[]' value='$id'>
</div>
</td>
</tr>
</table>";
}
print "<input type='submit' name='submit' value='Delete' title='Delete checked items'>"; ?>
</form>
<?php
if( isset($_POST['id']) )
{
$sql = "DELETE FROM $table WHERE link=$id AND userid='$username'";
$result = mysql_query($sql);
}
?>