I need help with setting up my array. What the code needs to do is if you click on one of the checkboxes it should return what you have ordered and the price which are .25 cents per item. I have figured out how to get it to show what the item is that is clicked on. For example if someone chooses chicken it will echo what they ordered which is chicken, but I have absolutely no idea how and where to add in a price for each of the items and only show the price for the items they picked and totaled up. Please help, I'm stuck.


Please select your pizza toppings Pepperoni
Ground beef



<?php echo "You order a pizza with
"; foreach($_POST[options] as $ingredients){ echo"With $ingredients
"; } ?>



i added a little to your script, this should do what you need:

//Handle the form
$perTopping = .25; // .25 pence/cents per topping.
$extraToppings = count($_POST[‘options’]); // count how many toppings

// show the price for the individual toppings cost
echo '<p>Extra toppings cost ' . $perTopping . ' each</p>';

echo 'You ordered a ';
// check if any extra toppings?
if($extraToppings == 0)
	echo "plain pizza."; // no extra toppings 
	echo 'pizza with ' . $extraToppings . ' extra toppings<br>'; // we want a nice pizza :)

// display the toppings
foreach($_POST['options'] as $ingredients)
	echo "$ingredients<br>";

// subtotal:
$toppingsTotal = number_format($perTopping * $extraToppings, 2);
echo '<p>Toppings Total: ' . $toppingsTotal . '</p>';

} // End of submission IF
[php]// output based on 3 toppings chosen:
Extra toppings cost 0.25 each

You ordered a pizza with 3 extra toppings
Toppings Total: 0.75[/php]

hope this helps

Sponsor our Newsletter | Privacy Policy | Terms of Service