(基础)Web服务端脚本编写示例 图书售卖系统示例

由于一些插入图片出错...一直都不能正常看。编辑文章这个应该把代码灰色在明显一点-_-...

main.html:

<html>
<head>
 <title>Welcome to book seller</title>
</head>

<body>
	<form action = "process.php" method = "post">
		<h2>Welcome!</h2>

		<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>please fiil in the quantify field of the following form</p>
		<table border = "border">
			<tr>
				<th>book</th>
				<th>publisher</th>
				<th>price</th>
				<th>quantitiy</th>
			</tr>
			<tr>
				<td>Web technology</td>
				<td>Springer press</td>
				<td>$5.0</td>
				<td><input type = "text" name = "web_t" size = "7" /></td>
			</tr>
			<tr>
				<td>mathematics</td>
				<td>ACM press</td>
				<td>$6.2</td>
				<td><input type = "text" name = "math" size = "7" /></td>
			</tr>
			<tr>
				<td>principle of OS</td>
				<td>Science press</td>
				<td>$10</td>
				<td><input type = "text" name = "os" size = "7" /></td>
			</tr>
			<tr>
				<td>Theory of matrix</td>
				<td>High education press</td>
				<td>$7.8</td>
				<td><input type = "text" name = "matrix" size = "7" /></td>
			</tr>
			</table>

		<h3>Payment method</h3>
			<p>
			<input type = "radio" name = "payment" value = "cash" chexked = "unchecked" />
			cash <br/>
			<input type = "radio" name = "payment" value = "cheque" chexked = "unchecked" />
			cheque <br/>
			<input type = "radio" name = "payment" value = "credit card" chexked = "unchecked" />
			credit card <br/>

			<input type = "submit" value = "submit" />
			<input type = "reset" value = "reset" />

		</p>
		</form>
</body>
</html>

process.php:

<html>
<head>
	<title>This is the output of process.php</title>
</head>

<body>
	<?php
		$name = $_POST["name"];
		$address = $_POST["address"];
		$zip = $_POST["zip"];
		$web_t = $_POST["web_t"];
		$math = $_POST["math"];
		$os = $_POST["os"];
		$matrix = $_POST["matrix"];
		$payment = $_POST["payment"];

		if($web_t == "") $web_t = 0;
		if($math == "") $math = 0;
		if($os == "") $math = 0;
		if($matrix == "") $matrix = 0;

		$web_t_cost = 5.0*$web_t;
		$math_cost = 6.2*$math;
		$os_cost = 10*$os;
		$matrix_cost = 7.8*$matrix;
		$total_num = $web_t+$math+$os+$matrix;
		$total_price=$web_t_cost+$math_cost+$os_cost+$matrix_cost;
	?>
	<?php
		printf("Your name:$name <br/> your address:$address <br/> Your zip:$zip<br/>")
	?>
	<p/>
	<table border = "border">
		<tr>
			<th>book</th>
			<th>publisher</th>
			<th>quantity</th>
			<th>total</th>
		</tr>
	<?php if($web_t != 0) { ?>
		<tr>
			<td>Web technology</td>
			<td>Springer press</td>
			<td>
				<?php print($web_t);?>
			</td>
			<td>
				<?php printf("$ %4.2f", $web_t_cost);?>
			</td>
		</tr>
	<?php } ?>
	<?php if($math != 0) { ?>
		<tr>
			<td>mathematics</td>
			<td>ACM press</td>
			<td>
				<?php print($math);?>
			</td>
			<td>
				<?php printf("$ %4.2f", $math_cost); ?>
			</td>
		</tr>
	<?php } ?>
	<?php if($os != 0) { ?>
		<tr>
			<td>Theory of matrix</td>
			<td>High education press</td>
			<td><?php print($os);?> </td>
			<td>
				<?php printf("$ %4.2f", $os_cost); ?>
			</td>
		</tr>
	<?php } ?>
	<?php if($matrix !=0) { ?>
		<tr>
			<td>Theory of matrix</td>
			<td>High education press</td>
			<td><?php print($matrix);?> </td>
			<td>
				<?php printf("$ %4.2f", $matrix_cost); ?>
			</td>
		</tr>
	<?php } ?>
	</table>

	<?php printf("%s has bought %d books<br/>", $name, $total_num) ?>
	<?php printf("%s paid %.4f <br/>", $name, $total_price) ?>
	<?php printf("paid by %s <br/>", $payment) ?>

	<?php
	$file = fopen("customer.txt", "a");
	fwrite($file, "$name has bought $total_num books\r\n");
	fwrite($file, "$name paid $total_price\r\n");
	fwrite($file, "paid by $payment\r\n");
	?>
</body>
</html>

这是南邮web技术第二次实验。

设计一个图书售卖系统。

编写了一个main.html和一个process.php合作实现预期的功能。

由于插入图片老是使文章排版乱。就不放图了。

<pre name="code" class="html">
				
时间: 2024-08-29 15:17:41

(基础)Web服务端脚本编写示例 图书售卖系统示例的相关文章

(基础)Web数据库访问编写简单示例——图书售卖系统示例2

南邮web技术的第三次实验,看起来与上次第二次的内容差别不大,但这次要访问数据库.用php连接的数据库. 代码如下:(分为main.html.process.php.order_query.html.process_query.php) mian.html <html> <head> <title>Welcome to book seller</title> </head> <body> <form action = "

如何提高Web服务端并发效率的异步编程技术

作为一名web工程师都希望自己做的web应用能被越来越多的人使用,如果我们所做的web应用随着用户的增多而宕机了,那么越来越多的人就会变得越来越少了,为了让我们的web应用能有更多人使用,我们就得提升web应用服务端的并发能力.那么我们如何做到这点了,根据现有的并发技术我们会有如下选择: 第一个做法:为每个客户端发送给服务端的请求都开启一个线程,等请求处理完毕后该线程就被销毁掉,这种做法很直观,但是在现代的web服务器里这种做法已经很少使用了,原因是新建一个线程,销毁一个线程的开销(开销是指占用

搭建一个java web服务端

最近也是做了一个简单的java web 项目,由于以前也是没接触过,在这里记录下搭建一个web服务端的过程. 一般我们做一个服务端要么在本地自己的电脑上先安装环境,一般是windows系统,主要安装jdk + tomcat + mysql,这些安装教程网上都有,也很简单,我这里就不多说了,我要讲的是在一个远程linux服务器上搭建web服务端环境. 对于一个liunx服务器,我们可以使用xshell等终端工具登录来操作远程服务器,使用xshell的好处是,我们可以使用rz ,sz命令上传上载文件

winform客户端利用webClient实现与Web服务端的数据传输

由于项目需要,最近研究了下WebClient的数据传输.关于WebClient介绍网上有很多详细介绍,大概就是利用WebClient可以实现对Internet资源的访问.无外乎客户端发送请求,服务端处理请求.回应请求.所以,我下面就简单描述下学习过程中遇到的一些问题: 1.关于Winform客户端请求 WebClient wc = new WebClient();//初始化webclient string path = "http://192.168.1.115:8089/Handler1.as

Android服务端开发1-使用Eclipse搭建Java Web服务端

本篇博客介绍如何使用Eclipse来创建一个Java Web程序,为后面讲通过Android客户端跟服务端进行交互打下基础,关于服务端可以选用的程序很多,主流的搭配是Android客户端+PHP服务端,我们也可以使用Android客户端+Java EE服务端这样的搭配,就看公司是以哪种方式提供了. 创建一个Java Web程序,没有特别复杂的流程,我们先准备一下原材料: 1. Eclipse(注:这个不是ADT Bundle,最好到官网下载针对开发Java EE的IDE,如果可以的话,选中MyE

Web服务端开发需要考虑的问题

API设计 是否Restful. 首先需要清楚,Restful是一种风格而不是规范,不存在必须遵守的问题. Restful本质上是对HTTP API进行有效的分类. 分类是应该的,可以让API组织变得有序.层次清晰 一定要以Restful的风格分类吗? Restful风格的特点 url表示的只是资源,没有动作,所以只会出现名词,不会出现动词 这样的url不对 /accounts/1/transfer/499 应该是这样 /accounts/1/transactions/499 想想传统的logi

七牛云存储android客户端及java服务端代码编写

前一篇博客提到让我很伤心的c应用,由于是一款供用户上传图片的应用,因此必须解决图片存储问题,如果直接将图片存储至服务器,当用户上传图片较多,服务器空间将很快吃紧,同时也没有那么大的带宽,现实中我买的阿里云服务器是最低配置,数据盘才20G,带宽才1M,如果用这样配置的服务器做图片存储,那实在太扯了.于是很自然的想到用图片云存储服务器,通过不断查找资料,最后将目标定位在七牛云和又拍云.在做选择时,主要对比了两者之间的价格及技术优势,也看了很多相关话题讨论,个人认为这两者无论从技术方案还是产品价格,都

WEB服务端安全---注入攻击

注入攻击是web领域最为常见的攻击方式,其本质是把用户输入的数据当做代码执行,主要原因是违背了数据与代码分离原则,其发生的两个条件:用户可以控制数据输入:代码拼接了用户输入的数据,把数据当做代码执行了. 下面是几种常见注入攻击及其防御方法: SQL注入及常见攻击技巧 经典注入  如: $username = $_POST['username']; $sql = "select * from usertable where username="."'".$userna

web服务端安全---文件上传漏洞

1.简述 文件上传漏洞是指用户上传了一个可执行的脚本文件,并通过此脚本文件获得了执行服务端命令的能力.这种攻击方式是最直接和有效的,而且互联网中我们经常会用到文件上传功能,它本身是没有问题的,正常的业务需求,可是文件上传后服务器如果不能安全有效的处理或解释文件,往往会造成严重的后果. 常见的安全问题: 上传文件是web脚本语言,服务器的web容器解释并执行了用户上传的脚本,导致代码执行: 上传文件是flash的策略文件crossdomain.xml,黑客用以控制flash在该领域下的行为: 上传