0

I am facing a problem with the following error if I unselecked the checkbox..

Notice: Undefined index: choice in C:\xampp\htdocs\test.php on line 15

Notice: Undefined index: choice in C:\xampp\htdocs\test.php on line 18 Bye Bye indranil

here is my code

<html>
<head>

<form action="test.php" method="post">
<input type="checkbox" name="choice" value="indranil" />Indranil<br />

<input type="submit" name="submit" value="submit" />
</form>


<?php 
 if(isset($_POST['submit']))
{

 if ($_POST['choice']=="indranil") 
{          
 echo "Hello indranil";      
}
 if ($_POST['choice']!="indranil") 
{

  echo "Bye Bye indranil";

}   
}       
?>
</body>
</html>

Please help me with a proper explanation and proper code because I am a begginer in php. Thank You.

Indranil
  • 53
  • 4
  • you need to use `isset($_POST['choice'])` because the browser doesn't send that field if it is not checked – cmorrissey Jun 08 '17 at 18:31
  • If you dont check a checkbox... It is not sent to the PHP in the `$_POST` array. So you always have to check for its existance using `isset` – RiggsFolly Jun 08 '17 at 18:31

0 Answers0