need help in using adding the total check in checkbox in php?

  • Thread starter Thread starter MYsweet
  • Start date Start date
M

MYsweet

Guest
this is my code now i want to add all the prices of items i checked can anyone help me using foreach
this will make an output if you check 2 boxes it will print "You selected 2 item(s).
Now i want to get the prices of the selected items i want to make an output if you selected coffee and milk it will print
"You selected 2 item(s)"
the total is 85

<html>
<body>


<form action="vendor.php" method="post">
<h3> Select Drinks </h3><br />
<input type="checkbox" name="vend[]" value="coffee" />COFFEE (50)<br />
<input type="checkbox" name="vend[]" value="milk" />MILK (35)<br />
<input type="checkbox" name="vend[]" value="chocolate" />CHOCOLATE (80)<br />
<input type="checkbox" name="vend[]" value="tea" />TEA (50)<br />
<input type="checkbox" name="vend[]" value="mocha" />MOCHA (65)
<input type="submit" name="formSubmit" value="Submit" />
</form>



<?php
$drinks = $_POST['vend'];
$price =0;

if(empty($drinks))

{
echo("You didn't select any drinks.");
}
else
{
$N = count($drinks);


echo("You selected $N item(s):");
}


?>

</body>
</html>
 
Back
Top