Wee present from me to you

*EDIT I made a mistake by typing AS instead of as - full code can be found 2 posts down

CODE
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
//You need the delete above the select to show your changes instantly
if(sizeof($_GET['delete'])){
foreach($_GET['delete'] AS $dId){
$delete = mysql_query("delete from items where itemid = ".(int)$dId) or die('crap'); //Adding an (int) will help avoid SQL errors
}
}
//$sql = "select * from items where userid = '".$_session['id']."' "; - doesn't seem to be used
$result = mysql_query("select itemid, item from items where userid = ".(int)$_SESSION['id']) or die('summit went wrong'); // changes the userid = to an integer input, and added only the required columns to the SQL select to help speed up your system
$count = mysql_num_rows($result);
if($count <1){
print("<tr><td colspan=\"2\"><center>You currently have no items.<center></td></tr>");
}else{
while($item = mysql_fetch_array($result)){
print("<tr><td><center>".$item['item']."</center></td><td width=\"40%\"><center>".$item['itemid']."</center></td><td width=\"10$\">
<input type=\"checkbox\" name=\"delete[]\" value=".$item['itemid'].">
</td></tr>
<tr><td colspan='3'><p align='right'><input type='submit' name='delete' value='delete!'</p></td></tr>");
}
}
?>
<input type="submit" name="del_btn" id="del_btn" value="Delete" />
</form>
Basically, you assign your checkbox names to an array which is posted, then using a foreach you can loop through each checkbox and pull its value, removing it from the database. I updated the SQL statement so that you are only requesting column names that are required at this stage as it will speed up your application (you should never really use the SELECT *).
In the WHERE clause, I removed the single quotes from the userid = as I assumed this was an int field - if this is wrong just undo my changes on that section.
Hope it works out well for ya
This post has been edited by pemcconnell: 30 Sep, 2008 - 05:24 AM