实验内容及要求
1 、显示一个图书售卖界面,主要包括一下内容
(1)HTML 的标题为“Welcome to book seller”。
(2)页面内容第一行黑体显示“You are welcome”。
(3)标签提示“please input your name”,并创建输入框。
(4)标签提示“please input your address”,并创建输入框。
(5)标签提示“please input your zip”,并创建输入框。
(6)黑体显示“please fill in the quantity field of the following form”。
(7)表格分成四列,分别是“book”,“publisher”,“price”,“quantity”,,其中包含的信息如
1 、显示一个图书售卖界面,主要包括一下内容
(1)HTML 的标题为“Welcome to book seller”。
(2)页面内容第一行黑体显示“You are welcome”。
(3)标签提示“please input your name”,并创建输入框。
(4)标签提示“please input your address”,并创建输入框。
(5)标签提示“please input your zip”,并创建输入框。
(6)黑体显示“please fill in the quantity field of the following form”。
(7)表格分成四列,分别是“book”,“publisher”,“price”,“quantity”,,其中包含的信息如
表格所示
(8)quantity 采用输入框输入。
(9)显示“payment method”
(10)用单选按钮显示四个支付方式选项“cash”,“cheque”,“credit card”。
(11)显示两个标准按钮,“submit”按钮和“reset”按钮。
2 、当用户输入完各个内容并按下“submit”按钮后,通过脚本生成新的HTML 页面。其中
包含以下内容
(1)customer name
(2)customer address
(3)customer zip
(4)以表格形式显示订购图书信息,包含四列“book”,“publisher”,“price”,“total cost”,
其中 total cost 通过脚本动态计算生成。
(5)计算并显示“××has bought××books”。(××分别指代客户名字和购买书的数量)
(6)计算并显示“××paid××”。(这里××指代客户名字和总金额数)
(7)根据用户的选择显示“paid by××”。(这里×指代用户选择的支付方式)
3 、将用户购买信息存入到文件中,每个客户包含三行信息,即2 中的(5)(6)(7)三句话。
4 、如果用户按的是“重置”按钮,则清除所有的输入信息。
<html>
<head>
<title>
Welcome to book seller
</title>
</head>
<body>
<form action = "seller.php" method = "post">
<h1>YOU are weclome</h1>
<table>
<tr>
<td>please input your name</td>
<td><input type = "text" name = "name" size = "30"/></td>
</tr>
<tr>
<td>please input your address</td>
<td><input type = "text" name = "address" size = "30"/></td>
</tr>
<tr>
<td>please input your zip</td>
<td><input type = "text" name = "zip" size = "30"/></td>
</tr>
</table>
<p>
<strong>please fill in the quantity field of the following form</strong>
</p>
<table border = "border">
<tr>
<th>book</th>
<th>publisher</th>
<th>prise</th>
<th>quantity</th>
</tr>
<tr>
<th>Web technology</th>
<td>Springer</td>
<td>$5.0</td>
<th><input = "text" name = "web"/></th>
</tr>
<tr>
<th>mathematics</th>
<td>ACM press</td>
<td>$6.2</td>
<th><input = "text" name = "mathematic"/></th>
</tr>
<tr>
<th>principle of OS</th>
<td>Science press</td>
<td>$10</td>
<th><input = "text" name = "OS"/></th>
</tr>
<tr>
<th>Theory of matrix</th>
<td>High education press</td>
<td>$7.8</td>
<th><input = "text" name = "matrix"/></th>
</tr>
</table>
<h3>Payment method:</h3>
<p>
<input type = "radio" name = "payment" value = "cash" checked = "checked"/>Cash
<input type = "radio" name = "payment" value = "cheque"/>cheque
<input type = "radio" name = "payment" value = "cc"/>credit card
<input type = "radio" name = "payment" value = "Alipay"/>Alipay
</p>
<p>
<input type = "submit" value = "Submit"/>
<input type = "reset" value = "Reset"/>
</p>
</form>
</body>
</html>
<html>
<head>
<title>process the seller.html form</title>
</head>
<body>
<?php
$web = $_POST["web"];
$mathematic = $_POST["mathematic"];
$OS = $_POST["OS"];
$matrix = $_POST["matrix"];
$name = $_POST["name"];
$address = $_POST["address"];
$city = $_POST["zip"];
$payment = $_POST["payment"];
if($web == "") $web = 0;
if($mathematic == "") $mathematic = 0;
if($OS == "") $OS = 0;
if($matrix == "") $matrix = 0;
$web_cost = 5.0 * $web;
$mathematic_cost = 6.2 * $mathematic;
$OS_cost = 10 * $OS;
$matrix_cost = 7.8 * $matrix;
$totle_price = $web_cost + $mathematic_cost + $OS_cost + $matrix_cost;
$totle_items = $web + $mathematic + $OS + $matrix;
?>
<h4>costomer:</h4>
<?php
print("$name<br/> $address<br/> $city<br/>");
?>
<p/><p/>
<table border = "border">
<caption>Order imformation</caption>
<tr>
<th>book</th>
<th>publisher</th>
<th>price</th>
<th>total cost</th>
</tr>
<tr align = "center">
<td>Web technology</td>
<td>Springer</td>
<td>$5.0</td>
<td><?php printf("$%4.2f",$web_cost)?></td>
</tr>
<tr align = "center">
<td>mathematics</td>
<td>ACM press</td>
<td>$6.2</td>
<td><?php printf("$%4.2f",$mathematic_cost)?></td>
</tr>
<tr align = "center">
<td>principle of OS</td>
<td>Science press</td>
<td>$10</td>
<td><?php printf("$%4.2f",$OS_cost)?></td>
</tr>
<tr align = "center">
<td>Theory of matrix</td>
<td>High education press</td>
<td>$7.8</td>
<td><?php printf("$%4.2f",$matrix_cost)?></td>
</tr>
</table>
<p/><p/>
<?php print "$name has bought $totle_items books<br/>";
printf("$name paid $%5.2f<br/>",$totle_price);
print "paid by $payment<br/>";
?>
<?php
$myfile = fopen("newfile.txt", "a") or die("Unable to open file!");
$txt = "$name has bought $totle_items books\r\n";
fwrite($myfile, $txt);
$txt = "\n$name paid $totle_price\r\n";
fwrite($myfile, $txt);
$txt = "\npaid by $payment\r\n";
fwrite($myfile,$txt);
fclose($myfile);
?>
</body>
</html>