i am trying to create a restaurant order summary where the customer can select his order via CheckBox and quantity and get the sum of prices at the End. I just can't seem to figure out how to add the quantity to my code. It is saying at the end : You have selected Chicken (for example) I want it to say: You have selected 5 Chicken Here it is:
<body>
<h3>Select what you want to eat</h3>
<form action="PlaceOrder.php" method="get"/>
<input type="checkbox" name="choice[]" value="1"/>Chicken,Price:8
<input name="quantity[]" type="text" /><br />
<input type="checkbox" name="choice[]" value="2"/>Meat,Price:3<br />
<input type="checkbox" name="choice[]" value="3"/>Souvlaki,Price:2.50<br />
<input type="checkbox" name="choice[]" value="4"/>Pizza,Price:12<br />
<input type="submit" value="Order"/>
</form>
and php:
<?php
if(isset($_GET["choice"])){
$food=$_GET["choice"];
$quantity=$_GET["quantity"];
$c = count($food);
$price = 0.0;
for ($i=0; $i<$c ; $i++){
if ($food[$i] == 1){
$price = $price + 8;
//here it's not working with quantity
echo "You have selected " .$quantity." Chicken <br>";
}
if ($food[$i] == 2){
$price = $price + 3;
echo "You have selected Meat <br>";
}
if ($food[$i] == 3){
$price = $price + 2.5;
echo "You have selected Souvlaki <br>";
}
if ($food[$i] == 4){
$price = $price + 12;
echo "You have selected Pizza <br>";
}
}
echo "Total: ".$price . "<br>";
}
else {
echo "Please select something!";
}
?>
</body>
Aucun commentaire:
Enregistrer un commentaire