收藏 分销(赏)

2023年南京邮电大学双语web实验二报告.docx

上传人:二*** 文档编号:4517707 上传时间:2024-09-26 格式:DOCX 页数:8 大小:297.71KB
下载 相关 举报
2023年南京邮电大学双语web实验二报告.docx_第1页
第1页 / 共8页
本文档共8页,全文阅读请下载到手机保存,查看更方便
资源描述
第四章 实验 2 Web 服务端脚本编写 一 实验目的 (1)通过上机实践,熟悉 Apache 服务器的安装和配置使用方法。 (2)掌握 PHP 脚本语言,纯熟运用 PHP 语言进行服务器端编程。 二 实验环境 硬件:Macbook Pro13.3 2023early 软件:Apache+MySQL+PHP7.1.8 编辑器:Sublime Text 三 实验内容及规定 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)三句话。 假如用户按的是“重置”按钮,则清除所有的输入信息。 四 实验过程 1 编写 index.html,重要涉及一下内容 (1)采用 HTML 的head 表达。 <head> <title>Welcome to book seller</title> </head> (2)采用<h1>标签。 <h1>You are wekcome!</h1> (3)(4)(5)采用<tr></tr>中嵌套<td></td>,<td></td>中嵌套 input 标签实现。 (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 Card<br> (11)用<input type=”submit”>和<input type=”reset”>实现。 <input type="submit" value="Submit"> <input type="reset" name="Reset"> 2 编写 main.php,采用一下技术环节 (1)(2)(3)用户的输入值采用 PHP 脚本的$_POST 函数获取。 $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; (5)(6)(7)print 或者printf 显示。 <?php print "$Name has bought $total_items books. "; ?> <br> <?php print" $Name paid $total_price books. "; ?> <br> <?php print" paid by $Payment. "; ?> 五 实验结果 界面显示 实验结果分析与体会 写了两年的代码,第一次感觉到php调试非常不容易,除了个别的就没有犯错。我在实验中将form的位置调错导致了name、address和zip的变量无法互相传递,刚开始认为是print的问题,结果换成了echo也没有效果,最后幸运的是发现了问题所在。尚有一个就是php的语法问题吧,忘掉分隔号了,然后在mamp上运营的结果就是无法显示该页面error500,所以写php时应当格外小心变量和符号,当你写C++或者Java的时候IDE会提醒你写错了,但是写php用文本编辑的时候和少提醒你这种错误。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 教育专区 > 远程教育/电大

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服