clausowitz Posted July 15, 2011 Share Posted July 15, 2011 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'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242045-error-message-when-no-checkbox-was-checked/ Share on other sites More sharing options...
trq Posted July 15, 2011 Share Posted July 15, 2011 Check the index exists first using isset. Quote Link to comment https://forums.phpfreaks.com/topic/242045-error-message-when-no-checkbox-was-checked/#findComment-1243005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.