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';
 }
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.