Archive for the 'PHP & MySQL' Category

checkbox code:
<input name=’checkbox[]‘ type=’checkbox’ id=’checkbox[]‘ value=\”".$row['id'].”\”>

Browser output:
<input name=’checkbox[]‘ type=’checkbox’ id=’checkbox[]‘ value=”392″>

Button at the bottom of form:
<input name=’delete’ type=’submit’ id=’delete’ value=’Delete multiple Selected items’>

CODE:
if($delete){
$delete = $_REQUEST['delete'];
$checkbox = $_REQUEST['checkbox'];
$count = count($_REQUEST['checkbox']);
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = “DELETE FROM $tbl_name WHERE id=’$del_id’”;
$result = mysql_query($sql);
}

// if successful refresh page
if($result){
echo “<meta http-equiv=\”refresh\” content=\”0;URL=checkbox.php\”>”;
}