第四章 实验 2 Web 服务端脚本编写

exe2.html

<html>
  <head>
   <title> Welcome to book seller</title>
  </head>
  <body>
  <form action="exe2.php"
  method="post">
 <!--greetings-->
  <p><h3>You are welcome</h3></p>
  <hr/>

<!--personal information-->
  <table>
  <tr>
     <td><B>please input your name:</B></td>
	 <td><input type="text" name="name" size="15"  /></td>
  </tr>
  <tr>
	 <td><B>please input your address:</B></td>
	 <td><input type="text" name="address" size="15"  /></td>
  </tr>
  <tr>
	 <td><B>please input your zip:</B></td>
	 <td><input type="text" name="zip" size="15"  /></td>
  </tr>
	 </table>
	 <hr/>

<!--purchase information -->
    <h3>please fill in the quantity field of the following form</h3>
    <table border="1">
    <caption><h4>purchase information</h4></caption>

    <tr>
	  <td>book</td>
	  <td>publisher</td>
	  <td>price</td>
	  <td>quantity</td>
	</tr>

	 <tr>
	  <td>Web technology</td>
	  <td>Springer pres</td>
	  <td>$5.0</td>
	  <td><input type="text" name="webnum" size="5"/></td>
	</tr>

	 <tr>
	  <td>mathematics</td>
	  <td>ACM press</td>
	  <td>$6.2</td>
	  <td><input type="text" name="mathnum" size="5"/></td>
	</tr>

	 <tr>
	  <td>principle of OS </td>
	  <td>Science press</td>
	  <td>$10</td>
	  <td><input type="text" name="OSnum" size="5"/></td>
	</tr>

	
	 <tr>
	  <td>Theory of matrix</td>
	  <td>High education press</td>
	  <td>$7.8</td>
	  <td><input type="text" name="matrixnum" size="5"/></td>
	</tr>
  
  </table>
  <br/>
  <hr/>

  <!-- payment method-->
  <h3>payment method</h3>
  <input type="radio" name="paymet" checked="checked" value="cash" />cash<br/>
  <input type="radio" name="paymet" value="cheque"/>cheque<br/>
  <input type="radio" name="paymet" value="credit"/>credit card<br/><br/>
  <hr/>

  <!--submit and reset -->
  <input type="submit" value="Submit Order"/>
  <input type="reset" value="Clear Order Form"/>
  </form>
  </body>
</html>

exe2.php

<html>
  <head>

    <?php
	  $name=$_POST["name"];
	  $address=$_POST["address"];
	  $zip=$_POST["zip"];
	  $webnum=$_POST["webnum"];
      $mathnum=$_POST["mathnum"];
	  $OSnum=$_POST["OSnum"];
	  $matrixnum=$_POST["matrixnum"];
	  $paymet=$_POST["paymet"];

	  if($webnum=="")   $webnum=0;
	  if($mathnum=="")  $mathnum=0;
	  if($OSnum=="")    $OSnum=0;
	  if($matrixnum=="")$matrixnum=0;

	  $sum=$webnum+$mathnum+$OSnum+$matrixnum;

	  $webcost=$webnum*5;
	  $mathcost=$mathnum*6.2;
	  $OScost=$OSnum*10;
	  $matrixcost=$matrixnum*7.8;
	  $totalcost=$webcost+$mathcost+$OScost+$matrixcost;
	  ?>
	</head>
	<body>
     
	<h3>customer information</h3>
    <table>
	<tr><td><B>customer name:</B></td><td><?php print("$name");?></td></tr>
    <tr><td><B>customer address:</B></td><td><?php print("$address");?></td></tr>
    <tr><td><B>customer zip:</B></td><td><?php print("$zip");?></td></tr>
    </table>
    
	<?php if($sum) {?>
    <hr/>
	<h3>purchase information</h3>
	<table border="1")
	<tr>
	<td>book</td>
	<td>publisher</td>
	<td>price</td>
	<td>total cost</td>
	</tr>
	<?php } ?>
	<?php
	  if($webnum)
	  {
	    print("<tr><td>Web technology</td>");
	    print("<td>Springer pres</td>");
	    print(" <td>\$5.0</td>");
	    printf(" <td>$%5.2f</td></tr>",$webcost);
	  }
	?>
	<?php
	 if($mathnum)
	  {
	    print("<tr><td>mathematics</td>");
	    print("<td>ACM press</td>");
	    print(" <td>\$6.2</td>");
	    printf(" <td>$%5.2f</td></tr>",$mathcost);
	  }
	?>
	<?php
	  if($OSnum)
	  {
	    print("<tr><td>principle of OS</td>");
	    print("<td>Science press</td>");
	    print(" <td>\$10</td>");
	    printf(" <td>$%5.2f</td></tr>",$OScost);
	  }
	?>
	<?php
	  if($matrixnum)
	  {
	    print("<tr><td>Theory of matrix</td>");
	    print("<td>High education press</td>");
	    print(" <td>\$7.8</td>");
	    printf(" <td>$%5.2f</td></tr>",$matrixcost);
	  }
	?>
	<?php if($sum) {?></table> <?php } ?>
    <br/>
	<hr/>
	<h3> total information</h3>
	<?php
	printf("%s has bought %d books<br/>",$name,$sum);
	
	printf("%s paid $%5.2f<br/>",$name,$totalcost);
	
	printf("%s paid by %s",$name,$paymet);
	?>
	</body>
	</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值