mahenda Posted December 9, 2019 Share Posted December 9, 2019 I'm facing trouble on check box when register form is submitted without check the check button, but when the button is checked the error disappear . can you give me idea why and how to solve this issue. I saw many sites with such kind of button on registration form please any one who can solve this. Quote Link to comment https://forums.phpfreaks.com/topic/309662-undefined-index-on-check-box/ Share on other sites More sharing options...
Barand Posted December 9, 2019 Share Posted December 9, 2019 Only select check boxes (and radio buttons) are sent in the form data so you need you check if they are present using isset(). Example <?php for ($i=1; $i<=5; $i++) { if (isset($_GET['mycb'][$i])) { echo "Check box $i selected<br>" ; } } ?> <html> <head> <title>Example</title> </head> <body> <hr> <form> Check box 1 : <input type="checkbox" name="mycb[1]" value="1"><br> Check box 2 : <input type="checkbox" name="mycb[2]" value="2"><br> Check box 3 : <input type="checkbox" name="mycb[3]" value="3"><br> Check box 4 : <input type="checkbox" name="mycb[4]" value="4"><br> Check box 5 : <input type="checkbox" name="mycb[5]" value="5"><br><br> <input type="submit" name="btnSub" value="Submit"> </form> </body> </html> 1 Quote Link to comment https://forums.phpfreaks.com/topic/309662-undefined-index-on-check-box/#findComment-1572396 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.