PHPNewbie55 Posted March 12, 2009 Share Posted March 12, 2009 I would like to add a "compare" option to one of my pages. I have 28 items listed per page... Next to each item I would like to put a check box and a button at the bottom that when clicked would take you to a page that displays all the items that were checked on the form.... The problem I have -- or what I don't understand is how to use the info from each checked box to pull those products from the MySQL Database.. I have created several forms that do similar functions... but I always know what form elements are named and what the value is going to be... Example Form: <form id="form1" name="form1" method="post" action="compare.php"> <input type="checkbox" name="checkbox1" id="checkbox1" /> <input type="checkbox" name="checkbox2" id="checkbox2" /> <input type="checkbox" name="checkbox3" id="checkbox3" /> <input type="checkbox" name="checkbox4" id="checkbox4" /> <input type="checkbox" name="checkbox5" id="checkbox5" /> <input name="Submit" type="button" value="Compare Items" /> </form> So with the form above how would I extract the checked box info..?? Usually I know what the values are... and how many items to expect on the submit form.... But in this case I don't know how many items will be selected or what the values will be.. $????? = ($_POST["?????????"]); So how would I get that information on the submit form.....??? I hope this makes sense... any help would be appreciated....... Quote Link to comment https://forums.phpfreaks.com/topic/149178-solved-compare-form-elements/ Share on other sites More sharing options...
MadTechie Posted March 13, 2009 Share Posted March 13, 2009 Heres some options #1 <input type="checkbox" name="checkbox1" id="checkbox1" /> ifisset($_POST['checkbox1']) { echo "checkbox1 was checked"; } #2 <input type="checkbox" name="checkbox1" id="checkbox1" value="test" /> $data = $_POST['checkbox1']; //=test #3 <input type="checkbox" name="checkbox[1]" id="checkbox1" value="123"/> <input type="checkbox" name="checkbox[2]" id="checkbox2" value="456"/> <input type="checkbox" name="checkbox[3]" id="checkbox3" value="789"/> <input type="checkbox" name="checkbox[4]" id="checkbox4" value="abc"/> <input type="checkbox" name="checkbox[5]" id="checkbox5" value="def"/> foreach($_POST['checkbox'] as $K => $CB) { echo "checkbox $K was checked with the value '$CB'<br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/149178-solved-compare-form-elements/#findComment-783440 Share on other sites More sharing options...
angelcool Posted March 13, 2009 Share Posted March 13, 2009 It goes like this: <?php $checkbox=$_POST['checkbox1']; if ($checkbox==true) echo 'checked'; else echo 'NOT checked'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/149178-solved-compare-form-elements/#findComment-783442 Share on other sites More sharing options...
PHPNewbie55 Posted March 13, 2009 Author Share Posted March 13, 2009 Thank You!! Quote Link to comment https://forums.phpfreaks.com/topic/149178-solved-compare-form-elements/#findComment-783572 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.