Dimplistic Posted January 13, 2012 Share Posted January 13, 2012 This is the section of my form: <input type="checkbox" name="whatever[]" value="Book1"> <input type="checkbox" name="whatever[]" value="Book2"> <input type="checkbox" name="whatever[]" value="Book3"> And here is my php so far: $pricelist_book = 11.99; if(isset($_POST['whatever'])) { for ($i=0; $i<count($_POST['whatever']);$i++) { echo "<br />" . $_POST['whatever'][$i] . "<br /><br />". "(". "€". $pricelist_book . " " . "each" . ")" ."<br /><br />"; } } That should (I hope) pick up whatever was selected from the checkboxes (some or all) and display the price after it. (same price for each). However, what I would like to see is for it to display the price of 2 books or 3 books if selected. Quote Link to comment https://forums.phpfreaks.com/topic/254939-adding-up-a-total-based-on-selected-checkboxes/ Share on other sites More sharing options...
joel24 Posted January 13, 2012 Share Posted January 13, 2012 if they're the same price, then you'd just need $price = count($_POST['whatever']) * $bookPrice; Quote Link to comment https://forums.phpfreaks.com/topic/254939-adding-up-a-total-based-on-selected-checkboxes/#findComment-1307172 Share on other sites More sharing options...
Dimplistic Posted January 13, 2012 Author Share Posted January 13, 2012 if they're the same price, then you'd just need $price = count($_POST['whatever']) * $bookPrice; Thanks a lot for that. I inserted that but I was getting error messages. Where exactly do I place it? Quote Link to comment https://forums.phpfreaks.com/topic/254939-adding-up-a-total-based-on-selected-checkboxes/#findComment-1307173 Share on other sites More sharing options...
Dimplistic Posted January 13, 2012 Author Share Posted January 13, 2012 Oh it is working now thanks! Quote Link to comment https://forums.phpfreaks.com/topic/254939-adding-up-a-total-based-on-selected-checkboxes/#findComment-1307176 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.