我有一个显示带有单选按钮的项目的网站。我想让 PHP 代码在用户提交代码时显示总数。
以下是我目前拥有的代码以及商店中每件商品的价格。
<?php
$keybored = $_POST["keybored"];
$mouse = $_POST["mouse"];
$harddrive = $_POST["harddrive"];
$desktop = $_POST["desktop"];
$keyboredprice = 5.00;
$mouseprice = 3.50;
$hardriveprice = 20.00;
$desktopprice = 100;
$total = $prices;
echo "$total";
?>
我正在使用的 HTML 代码发布在下面,用于网络商店。
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: lightblue;}
h1 {color: gray;}
h2 {color: white;
border-size: 1;
width: 200px;
border: 15px solid black;
padding: 50px;
margin: 10px;}
p {color: white;
font-size: 200%;}
img {width:350px;height:300px;}
</style>
</head>
<body>
<form action="purchase.php" method="post">
<h1> Welcome to computer parts store</h1>
<h2>Keybored</h1>
<img src="keybored.jpg">
<p> Select how many <br>
<input type="radio" name="keybored" value="1"">1<br>
<input type="radio" name="keybored" value="2">2<br>
<input type="radio" name="keybored" value="3"> 3<br> <br>
</p>
<h2>Mouse</h1>
<img src="mouse.jpg">
<p> Select how many <br>
<input type="radio" name="mouse" value="1"">1<br>
<input type="radio" name="mouse" value="2">2<br>
<input type="radio" name="mouse" value="3"> 3<br> <br>
</p>
<h2>HarDrive</h1>
<img src="harddrive.jpeg" >
<p> Select how many <br>
<input type="radio" name="harddrive" value="1">1<br>
<input type="radio" name="harddrive" value="2">2<br>
<input type="radio" name="harddrive" value="3"> 3<br> <br>
</p>
<h2>Desktop</h1>
<img src="Desktop.jpg">
<p> Select how many <br>
<input type="radio" name="desktop" value="1">1<br>
<input type="radio" name="desktop" value="2">2<br>
<input type="radio" name="desktop" value="3"> 3<br> <br>
</p>
<p>
First Name: <input type="text" name="fname" ><br>
Last Name: <input type="text" name="lname" ><br>
Card type: <input type="text" name="type" > <br>
Card Number: <input type="text" name="Card" > <br>
Expiration date: <input type="text" name="exp" > <br>
<input type="submit" value="Submit order"><br>
</p>
</form>
</body>
</html>