rn14 Posted December 3, 2008 Share Posted December 3, 2008 Hi, I have an application where the user selects a number of people that they want to buy the product for. Based on this number their is a checkbox next to each product. The customer is then presented with 7 products of which they must select 5. I have written some simple if statements so that when the user selects the number of people this limits the the number of check boxes to the amount of people they have selected. To be clear, that means i have seven products on a page and if there are 3 people buying the products that will mean a total of 21 checkboxes. 7 for each person. Each person must select 5. My problem is trying to validate this to limit each person to picking 5 products: Here is what i have tryed: <?php session_start(); $num_of_people = $_SESSION['numofpeople']; //meal for 1 if($num_of_people == 1) { if (count($_POST['meal']) == 5) { echo '<META HTTP-EQUIV="Refresh" Content="0; URL=our_menustestw2.php">'; } //meal for 2 }elseif ($num_of_people == 2) { if (count($_POST['meal']) == 5 || count($_POST['meal2']) == 5) { echo '<META HTTP-EQUIV="Refresh" Content="0; URL=our_menustestw2.php">'; } //meal for 3 }elseif ($num_of_people == 3) { if (count($_POST['meal']) == 5 || count($_POST['meal2']) == 5 || count($_POST['meal3']) == 5) { echo '<META HTTP-EQUIV="Refresh" Content="0; URL=our_menustestw2.php">'; } //meal for 4 }elseif ($num_of_people == 4) { if (count($_POST['meal']) == 5 || count($_POST['meal2']) == 5 || count($_POST['meal3']) == 5 || count($_POST['meal4']) == 5) { echo '<META HTTP-EQUIV="Refresh" Content="0; URL=our_menustestw2.php">'; } //meal for 5 }elseif ($num_of_people == 5) { if (count($_POST['meal']) == 5 || count($_POST['meal2']) == 5 || count($_POST['meal3']) == 5 || count($_POST['meal4']) == 5 || count($_POST['meal5']) == 5) { echo '<META HTTP-EQUIV="Refresh" Content="0; URL=our_menustestw2.php">'; } }else echo '<META HTTP-EQUIV="Refresh" Content="0; URL=our_menustest.php">'; ?> What happens above is that when a first person buying selects five products the validation does not work. Not sure if i explained this clearly. Thanks for any help Quote Link to comment Share on other sites More sharing options...
rn14 Posted December 3, 2008 Author Share Posted December 3, 2008 Could anybody please help me with this?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.