Jump to content

error message when no checkbox was checked


clausowitz

Recommended Posts

I have some code to delete posted messages. However when no checkbox has been checked and I go to the delete page I get an error.

Unidentified index checkbox. Is there a way to prevent this?

 

<?php $outputList .=  '<td width="10%" ><div class="name" align="left"><input type="checkbox" name="checkbox[]" id="checkbox[]" value="' . $id . '" /></div></td>'; ?>

 

<?php

$checkbox = '';
$result = '';

if($_POST['delete']&& $_POST['checkbox'] <> '') // from button name="delete"
 {
$checkbox = $_POST['checkbox']; //from name="checkbox[]"
	 $countCheck = count($_POST['checkbox']);

for($i=0;$i<$countCheck;$i++)
	 {
		 $del_id  = $checkbox[$i];

$sql = "DELETE from bulletin_board where id = $del_id";
$result = mysql_query($sql);

	 }
		 if($result)
	 {	
			 header('Location: bb_index.php');
		 }
		 else
		 {
echo "Error: ".mysql_error();
		 }
 } else {
		 $msgToUser = '<br /><br /><font color="#FF0000">No messages were checked to delete.</font><p><a 	href="bb_index.php">Go Back</a></p>';
    include_once 'msgToUser.php';
 }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.