Ask Development Geography

How to use check boxes with if statements in php

Hie guys. Please help, i want to output text if a specific combination of two or more check boxes are checked using if statements or even a switch case in php. For example if the user checks Maths and Geography, the program will say “You qualify for a Honors Degree in wildlife management” Its more of a mini university counselling system. The problem is i can’t figure out how to use the “if” statement for individual check boxes.



<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
        What subjects did you pass at A 'Level?<br/>
        <input type="checkbox" name="subject[]" value="A" />Maths<br />
        <input type="checkbox" name="subject[]" value="B" />English<br />
        <input type="checkbox" name="subject[]" value="C" />Science<br />
        <input type="checkbox" name="subject[]" value="D" />Religious Education<br />
        <input type="checkbox" name="subject[]" value="E" />Geography

    <input type="submit" name="formSubmit" value="Submit" />

  $aSub = $_POST['subject'];
    echo("You didn't select any subjects.");
    $N = count($aSub);

    echo("You selected $N subject(s): ");
    for($i=0; $i < $N; $i++)
      echo($aSub[$i] . " ");


Leave a Reply

Your email address will not be published. Required fields are marked *