Dear all, I have check boxes like: <input type="checkbox" name="day" value="Saturday" /><br/> Satur <input type="checkbox" name="day" value="Sunday" /><br/> Sun <input type="checkbox" name="day" value="Monday" /><br/> Mon <input type="checkbox" name="day" value="Tuesday" /><br/> Tues <input type="checkbox" name="day" value="Wednesday" /><br/> Wednes <input type="checkbox" name="day" value="Thursday" /><br/> Thurs <input type="checkbox" name="day" value="Friday" /><br/> Fri PHP: I want to get all check boxes to be used in next page using POST method... How can I do that? Thank You in advance
<?php //Get the value of day. $day = $_POST['day']; ?> PHP: <?php //check if day is Sunday... if($_POST['day']=="Sunday"){ //proceed... } ?> PHP: <?php //check if day is selected... if($_POST['day']=="on"){ //proceed... } ?> PHP:
If I remember correctly you need to treat the POSTed variable as an array. But in order to do that you first need to change the name of the checkboxes to "day[]": <input type="checkbox" name="day[]" value="Saturday" /><br/> Satur <input type="checkbox" name="day[]" value="Sunday" /><br/> Sun <input type="checkbox" name="day[]" value="Monday" /><br/> Mon <input type="checkbox" name="day[]" value="Tuesday" /><br/> Tues <input type="checkbox" name="day[]" value="Wednesday" /><br/> Wednes <input type="checkbox" name="day[]" value="Thursday" /><br/> Thurs <input type="checkbox" name="day[]" value="Friday" /><br/> Fri HTML: The PHP code: <?PHP // Get POSTed array $day = $_POST['day']; //////////////////////// // EXAMPLE USAGE // //////////////////////// // If at least one element is present in the array if (count($day) > 0){ // For each element foreach ($day AS $dayName){ // Print it out print "$dayName Checked!<br>"; } } // Else notify the user that no elements were selected else { print "No days were checked!"; } ?> PHP: Just remember to validate values for stuff like this if you're using a DB to prevent SQL injection etc... EDIT: I've attached the above script in a PHP file for you so you can see it in action. I didn't bother wasting time to format it etc... but it'll give you the gist of it.