web | 实验 2 Web 服务端脚本编写

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”,其中包含的信息如
表格所示
表 4.1 图书样表
book publisher price quantity
Web technology Springer press $5.0
mathematics ACM press $6.2
principle of OS Science press $10
Theory of matrix High education press $7.8
(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>
	    <meta charset="UTF-8">
	    <title>Welcome to book seller</title>
	</head>
	<body>
	    <form action="second2.php" method="post">
		<table width="1000" align="center">
			<tr>
				<td>
				<p><br /><h1>You are welcome</h1></p>
				<table>
				<tr>
				<td><p>please input your name </td>    
				<td><label><input type="text" name="name"></label>    </td></p>
				</tr>
				<tr>
				<td><p>please input your address </td> 
				<td><label><input type="text" name="address"></label> </td></p>
				</tr>
				<tr>
				<td><p>please input your zip </td>     
				<td><label><input type="text" name="zip"></label>     </td> </p>
				</tr>
				</table><hr />
				</td>
			</tr>
		


            <tr>
				<td>
					<p><br /><h1>please fill in the quantity field of the following form</h1></p>
					<table  border="1" cellspacing="1">
						<tr>
							<td>book</td> 
							<td>publisher</td> 
							<td>price</td> 
							<td>quantity</td>
						</tr>
						 <tr>
							<td>Web technology</td> 
							<td>Springer press</td> 
							<td>$5.0</td> 
							<td><input type="text" name="quantity1"> </td>
						</tr>
						 <tr>
							<td>mathematics</td> 
							<td>publisher</td> 
							<td>$6.2</td>         
							<td><input type="text" name="quantity2"> </td>
						</tr>
						 <tr>
							<td>principle of OS</td> 
							<td>Science press</td> 
							<td>$10.0</td>  
							<td><input type="text" name="quantity3"> </td>
						</tr>
						<tr>
							<td>Theory of matrix</td> 
							<td>High education press</td> 
							<td>$7.8</td> 
							<td><input type="text" name="quantity4"> </td>
						</tr>
					    
					</table><hr />
				</td>
			</tr>


			<tr>
				<td>
					<p><br /><h1>payment method</h1></p>
					<p>
						<input type="radio" name="pm" value="cash">cash
						<input type="radio" name="pm" value="cheque">cheque
						<input type="radio" name="pm" value="creditcard">credit card
					</p><hr />
				</td>
			</tr>


            <tr>
				<td>
					<br />
					<input type="submit" value="submit" />
					<input type="reset" value="reset" />
					</table>
				</td>
		   </tr>

		</table>
		</form>
	</body>
</html>
<html>
    <head>
	    <meta charset="UTF-8">
		<title>Cashier</title>
	</head>

	<body>
        <?php
		    $name=$_POST["name"];
			$address=$_POST["address"];
			$zip=$_POST["zip"];

			$quantity1=$_POST["quantity1"];
			$quantity2=$_POST["quantity2"];
			$quantity3=$_POST["quantity3"];
			$quantity4=$_POST["quantity4"];

			$payment=$_POST["pm"];

			if($quantity1=="") $quantity1=0;
			if($quantity2=="") $quantity2=0;
			if($quantity3=="") $quantity3=0;
			if($quantity4=="") $quantity4=0;

			$quantity1_cost=5.0*$quantity1;
			$quantity2_cost=6.2*$quantity2;
			$quantity3_cost=10.0*$quantity3;
			$quantity4_cost=7.8*$quantity4;

			$total_item=$quantity1+$quantity1+$quantity1+$quantity1;
			$total_cost=$quantity1_cost+$quantity2_cost+$quantity3_cost+$quantity4_cost;
		?>
<table width="900" align="center">
		<tr><td>
		<h1> Cashier </h1>
		<hr />
		<?php
		    print("<strong>Customer Name    : </strong>$name <br /> 
			       <strong>Customer Address : </strong>$address <br /> 
				   <strong>Customer Zip     : </strong>$zip <br /><br />")
		?><hr />
</td></tr>

<tr><td>
		<table  border="1" cellspacing="1">
		    <caption> <strong>Order Information</strong> </caption>
						<tr>
							<td>book</td> 
							<td>publisher</td> 
							<td>price</td> 
							<td>quantity</td> 
							<td>total cost</td>
						</tr>
						 <tr>
							<td>Web technology</td> 
							<td>Springer press</td> 
							<td>$5.0</td> 
							<td><?php print ("$quantity1");?></td>
							<td><?php printf ("%.2f",$quantity1_cost);?></td>
						</tr>
						 <tr>
							<td>mathematics</td> 
							<td>publisher</td> <td>$6.2</td>         
							<td><?php print ("$quantity2");?></td>
							<td><?php printf ("%.2f",$quantity2_cost);?></td>
						</tr>
						 <tr>
							<td>principle of OS</td> 
							<td>Science press</td> <td>$10.0</td>  
							<td><?php print ("$quantity3");?></td>
							<td><?php printf ("%.2f",$quantity3_cost);?></td>
						</tr>
						<tr>
							<td>Theory of matrix</td> 
							<td>High education press</td> <td>$7.8</td> 
							<td><?php print ("$quantity4");?></td>
							<td><?php printf ("%.2f",$quantity4_cost);?></td>
						</tr>
					</table><br /><hr />
</td></tr>
<tr><td>
		<?php
		    print"$name has bought $total_item books .<br />";
			printf("$name paid : $ %5.2f .<br />",$total_cost);
			print"paid by $payment . ";
		?>
		</td></tr>
	</body>
</html>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值