当前位置:文档之家› 南京邮电大学双语web实验二报告2017

南京邮电大学双语web实验二报告2017

第四章实验 2 Web 服务端脚本编写一实验目的(1)通过上机实践,熟悉Apache 服务器的安装和配置使用方法。

(2)掌握PHP 脚本语言,熟练运用PHP 语言进行服务器端编程。

二实验环境硬件:Macbook Pro13.3 2015early软件:Apache+MySQL+PHP7.1.8编辑器:Sublime Text三实验内容及要求1显示一个图书售卖界面,主要包括一下内容(1)HTML的标题为“Welcome to book sel ler”。

(2)页面内容第一行黑体显示“Y ou are w elcome”。

(3)标签提示“plea se input your name”,并创建输入框。

(4)标签提示“plea se input your addre ss”,并创建输入框。

(5)标签提示“plea se input your zip”,并创建输入框。

(6)黑体显示“plea se fill in the quantity field of the follo w ing form”。

(7)表格分成四列,分别是“book”,“publi sher”,“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”,“publ ish er”,“price”,“totalcost”,其中t otal cost 通过脚本动态计算生成。

未购买的图书不显示。

(××分别指代客户名字和购买书的数。

(5)计算并显示“××ha s bought××bo oks”量)(6)计算并显示“××paid××”。

(这里××指代客户名字和总金额数)(7)根据用户的选择显示“paid by××”。

(这里×指代用户选择的支付方式)3将用户购买信息存入到文件中,每个客户包含三行信息,即2 中的(5)(6)(7)三句话。

如果用户按的是“重置”按钮,则清除所有的输入信息。

四实验过程1编写index.html,主要包括一下内容(1)采用HTML 的head 表示。

<head><title>Welcome to book seller</title></head>(2)采用<h1>标签。

<h1>You are wekcome!</h1>(5)采用<tr></tr>中嵌套<td></td>,<td></td>中嵌套input 标签实现。

(3)(4)(7)表格采用table 标签实现。

<table border="1px" padding="1px"><tr><th>book</th><th>publisher</th><th>price</th><th>quantity</th></tr><tr><td>Web technology</td><td>Spring Press</td><td>$5.0</td><td><input type="text" name="WT" size="30" /></td></tr><tr><td>Mathmatics</td><td>ACM Press</td><td>$6.2</td><td><input type="text" name="Ma" size="30" /></td></tr><tr><td>Principle of OS</td><td>Science Press</td><td>$10</td><td><input type="text" name="PO" size="30" /></td></tr><tr><td>Theory of Matrix</td><td>High Education Press</td><td>$7.8</td><td><input type="text" name="TM" size="30" /></td></tr></table>(8)输入框采用input。

<p>Please input your name:</p><input type="text" name="Cname" size="30" /><p>Please input your address:</p><input type="text" name="Caddress" size="30" /><p>Please input your zip:</p><input type="text" name="Czip" size="30" />(10)用<input type=”radio”>实现。

<input type="radio" name="payment" value="cash" checked="checked">Cash<br> <input type="radio" name="payment" value="cheque" >Cheque<br> <input type="radio" name="payment" value="creditcard" >Credit(11)用<input type=”submit”>和<input type=”reset”>实现。

<input type="submit" value="Submit"><input type="reset" name="Reset">2编写main.php,采用一下技术步骤(3)用户的输入值采用PHP脚本的$_P OS T 函数获取。

(2)(1)$Name = $_POST["Cname"];$Address = $_POST["Caddress"];$Zip = $_POST["Czip"];$WebTechnology = $_POST["WT"];$Mathmatic = $_POST["Ma"];$PrincipleOfOS = $_POST["PO"];$TheotyOfMatrix = $_POST["TM"];$Payment = $_POST["payment"];(4)数量通过$_POST 函数获取,动态计算生成。

if($WebTechnology =="") $WebTechnology=0;if($Mathmatic =="") $Mathmatic=0;if($PrincipleOfOS =="") $PrincipleOfOS=0;if($TheotyOfMatrix =="") $TheotyOfMatrix =0;$WT_cost = 5.0 * $WebTechnology;$Ma_cost = 6.2 * $Mathmatic;$PO_cost = 10 * $PrincipleOfOS;$TM_cost = 7.8 * $TheotyOfMatrix;$total_price = $WT_cost + $Ma_cost + $PO_cost + $TM_cost; $total_items = $WebTechnology +$Mathmatic + $PrincipleOfOS +$TheotyOfMatrix;(7)print 或者printf 显示。

(5)(6)<?phpprint "$Name has bought $total_items books. ";?><br><?phpprint" $Name paid $total_price books. ";?><?phpprint" paid by $Payment. "; >五实验结果界面显示实验结果分析与体会写了两年的代码,第一次感觉到php调试非常不容易,除了个别的就没有出错。

相关主题