php - radio button cannot empty -


this code radio button. want add condition, when 1 radio button not selected user, come out warning there data empty. when complete, count sum.

<form action="" method="post"> player 1: male <input type="radio" name="gender[1]" value="1"> female <input type="radio" name="gender[1]" value="2"> <br> player 2: male <input type="radio" name="gender[2]" value="1"> female <input type="radio" name="gender[2]" value="2"> <br> player 3: male <input type="radio" name="gender[3]" value="1"> female <input type="radio" name="gender[3]" value="2">  <br> <input type="submit" name="submit" value="submit"> </form>  <?php if (isset($_post['submit'])) {     $sum=0;     if (isset($_post['gender']))     {         $gender=$_post['gender'];         foreach ($gender $value)             {                $sum=$sum+$value;             }             echo $sum;      }     else     {         echo 'you did not choose genders';     } } ?> 

if radio buttons selected, count($_post['gender']) 3. replace

else {     echo 'you did not choose genders'; } 

with

if (count($_post['gender']) < 3) {      echo 'you did not choose genders'; } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -