HTML主要负责可以看见的部分
PHP负责看不见的后端
两者经常一起出现。今天倒腾了一晚上现在记录结果:
<html>
<head>
<meta charset="utf-8">
<title>YOU CAN DO IT!</title>
</head>
<body>
<form action="index.php" method="post">//这一行必须写不然脚本跑不起来action连接的是php文件名
<table broad="0">//为了好看
<tr>
<td width="150">Item</td>
<td width="15">Quantity</td>
</tr>
<tr>
<td>tireqty</td>
<td><input type="text" name="tireqty" size="3"></td>
</tr>
<tr>
<td>oilqty</td>
<td><input type="text" name="oilqty" size="3"></td>
</tr>
<tr>
<td colspan="3"><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
接下是PHP文件: (文件名 index.php)
<html>
<head>
<meta charset="UTF-8">
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<?php
$tireqty=0;
$oilqty=0;
//POST是特殊的超级全局变量,作用是获得得用户输入的值
if(isset($_POST['tireqty']) && isset($_POST['oilqty']))//防止报错
{
$tireqty=$_POST['tireqty'];
$oilqty=$_POST['oilqty'];
$totalqty=$tireqty*$oilqty;
echo "The result is "."$totalqty";
}
else include_once 'orderform.html';
?>
</body>
</html>