I need to edit the pizza.php file so that it calculates the cost of the order after clicking submit based off the selections. The html and css is added in order to let you run the code as I have it. Any solutions for the PHP file would be much appreciated.
Cost are as follows:
Size: large: $9.95, x-large: $12.95
Toppings: pepperoni $1.25, mushrooms $1.25
Crust: thin $0.00, original $0.00, deepdish $2.00
pizza.php
<?php
if(isset($_POST['submit'])){
$size=$_POST['size'];
$pepperoni=$_POST['pepperoni'];
$mushrooms=$_POST['mushrooms'];
$crust=$_POST['crust'];
$name=$_POST['name'];
$largeprice = 9.95;
$xlargeprice = 12.95;
$toppingsprice = 1.25;
if($crust == "Deepdish"){
$crustprice = 2.0;
}
else{
$crustprice = 0;
}
$file=fopen("pizza.txt", "a");
fwrite($file, $size);
fwrite($file, $pepperoni);
fwrite($file, $mushrooms);
fwrite($file, $crust);
fwrite($file, $name);
fclose($file);
echo"<h1>Pizza ordered, thank you $name!</h1>";
echo"<h1>Your total is </h1>";
}
?>
pizza.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pizza</title>
<link rel="stylesheet" type="text/css" href="pizza.css">
</head>
<body>
<div class="container">
<h1>Pizzazz Pizza</h1>
<br>
<form action="pizza.php" method="post">
<div class="formclass">
<div class="left">
<label for="">Size</label><br>
<input type="radio" value='Large' name="size">Large<br>
<input type="radio" value='X-Large' name="size">X-Large
</div>
<div class="middle">
<label for="">Toppings</label><br>
<input type="checkbox" value="Pepperoni" name="pepperoni">Pepperoni<br>
<input type="checkbox" value="Mushroom" name='mushrooms'>Mushrooms
</div>
<div class="right">
<label for="">Crust</label><br>
<select name="crust" id="">
<option value="">Select Crust</option>
<option value="Thin">Thin</option>
<option value="Original">Original</option>
<option value="Deepdish">Deep Dish</option>
</select><br>
</div>
</div>
<label for="">Name </label><input type="text" name="name">
<input type="submit" value="Submit" name="submit">
</div>
</body>
</html>
pizza.css
.container {
border: 5px black solid;
width: 600px;
height: 200px;
margin: auto;
padding: 25px;
background-color: rgb(218, 153, 56);
}
.container h1 {
text-align: center;
line-height: 0px;
}
.container input {
margin: 10px;
}
.left {
width: 40%;
height: 100px;
}
.middle {
width: 30%;
height: 100px;
}
.right {
width: 30%;
height: 100px;
}
.formclass {
display: flex;
}
source https://stackoverflow.com/questions/71710216/calculate-cost-of-order-based-on-selections-in-php
No comments:
Post a Comment