input - Radio buttons in PHP not working properly -


i have code:

<?php  if (isset($_post['ans'])) {     $answer = $_post['ans'];      if ($answer == "ans1") {                   echo 'correct';           }     else {         echo 'incorrect';     } } ?> <form action="example.php" method="post">   answer 1 <input type="radio" name="ans" value="ans1" /><br />   answer 2 <input type="radio" name="ans" value="ans2"  /><br />   answer 3 <input type="radio" name="ans" value="ans3"  /><br />   answer 4 <input type="radio" name="ans" value="ans4"  /><br />   <input type="submit" value="submit" /> </form> 

when select wrong button, tells me incorrect , when select right 1 tells me correct. problem if no button selected nothing happens. not echo incorrect or correct. if answer nothing should incorrect.

try add else if if button selected empty wil pass it.

    <?php if (isset($_post['ans'])) {     $answer = $_post['ans'];      if ($answer == "ans1") {                   echo 'correct';           }     else if(empty($answer)){         echo 'select button';     }     else {         echo 'incorrect';     }  } ?> 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

monitor web browser programmatically in Android? -

c# - Using multiple datasets in RDLC -