1 / 16

第 10 章 PHP 程序设计语言与网页程序的操作

第 10 章 PHP 程序设计语言与网页程序的操作. 主要内容 PHP 语言与网页表单 网页表单应用技术 网页程序传送数据方法. 7.1PHP 程序设计语言与网页的表单. 7.1.1PHP 语言与网页表单 客户端使用 IE 浏览器打开 html 网页 , 通过文本框、复选框等控件接收操作人员输入的数据和选项,当操作人员单击“提交”按钮后网页程序将把接收的数据传送到服务器,在传送的同时指定服务器一端由网页程序中表单( form ) action 选项中指定的 php 程序进行处理。. 7.1PHP 程序设计语言与网页的表单. 7.1.2 接收数据输入的网页程序

Télécharger la présentation

第 10 章 PHP 程序设计语言与网页程序的操作

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第10章PHP程序设计语言与网页程序的操作 主要内容 PHP语言与网页表单 网页表单应用技术 网页程序传送数据方法

  2. 7.1PHP程序设计语言与网页的表单 7.1.1PHP语言与网页表单 客户端使用IE浏览器打开html网页,通过文本框、复选框等控件接收操作人员输入的数据和选项,当操作人员单击“提交”按钮后网页程序将把接收的数据传送到服务器,在传送的同时指定服务器一端由网页程序中表单(form)action选项中指定的php程序进行处理。

  3. 7.1PHP程序设计语言与网页的表单 7.1.2接收数据输入的网页程序 创建表单form。 设置表单form,指定服务器端处理当前表单数据的php程序,在action选项中指明,确定表单数据的传送方式,在method选项中指明(GET方式和POST方式) <formname=“testform” method=“POST” action=“testsvr.php”> 摆放控件(文本框、单选按钮、复选框等)。 摆放“提交”按钮,和“重置”按钮。 <input name=“submit” type =“submit” value=“提交”> <input name=“reset” type =“reset” value=“重置”>(将控件值设置成初值)

  4. 7.1PHP程序设计语言与网页的表单 7.1.3PHP程序的功能与作用 • 检测来自前台的数据的合法性、有效性、完整性、一致性。 • 连接数据库(连接数据库服务器、打开数据库)。 • 选取数据、保存数据。 • Php程序通过$_POST[表单控件名]或$_GET[表单控件名]确认表单网页文件传送过来的数据。

  5. 7.1PHP程序设计语言与网页的表单 创建表单testfrm.htm <form name=“entertext” method=“GET” action=“testfrm.php”> <input name=“submit” type=“submit” value=“提交”> <input name=“reset” type=“reset” value=“重置”> </form>

  6. 7.1PHP程序设计语言与网页的表单 创建PHPtestfrm.php <?php Echo “客户端testfrm.htm程序中指定的当前程序”; ?>

  7. 表单控件练习题 表单文件control.htm 服务器文件control.php 文本框用于接收输入的数据 创建html网页文件control.htm,单击“设计” 插入表单,单击“插入”|“表单”|“表单”后产生一对表单标签<form></form>。 修改method选项和action选项 <body> <form name=“form1” method=“POST” action=“control.php”> </form> </body>

  8. 表单控件练习题 摆放两个按钮一个“提交”,一个“重置”按钮。 单击“插入”|“表单”|“按钮” <body> <form name=“form1” method=“POST” action=“control.php”> <input type="submit" name="Submitk" value="提交"> <input type=“reset” name=“resetk” value=“重置"> </form> </body>

  9. 7.2表单的文本框 输入“用户名”后单击“插入”|“表单”|“文本字段” 输入“密码”后单击“插入”|“表单”|“文本字段” <body> <form name=“form1” method=“POST” action=“control.php”> 用户名 <input type="text“ name=“userid“ size=“10” maxlength=“10” value=“20080001”> 密码 <input type=“password“ name=“userpwd“ size=“6” maxlength=“6”> </form> </body>

  10. 7.2表单的文本框 创建Control.php判断表单的用户名userid和密码userpwd文本框是否为空. <?php If (empty($_POST[userid])) die(“用户名不能为空”); If (empty($_POST[userpwd])) die (“密码不能为空”); If (strlen($_POST[userpwd])<>6) die(“密码长度必须6位”); ?> 注:$_POST必须大写

  11. 7.3表单的复选框 单击“插入”|“表单”|“复选框”插3个复选框。 <body> <form name=“form1” method=“POST” action=“control.php”> <input type=“checkbox” name=“chk1” value=“计算机基础”>计算机 <input type=“checkbox” name=“chk2” value=“网络数据库”>网络数据库 <input type=“checkbox” name=“chk3” value=“计算机通讯”>计算机通讯 </form> </body>

  12. 7.3表单的复选框 打开Control.php输出用户选中喜欢的课程 <?php Echo “您选中喜欢的课程有:".$_POST["chk1"]." ".$_POST["chk2"]." ".$_POST["chk3"]; ?> 注:$_POST必须大写

  13. 7.4表单的单选按钮 单击“插入”|“表单”|“单选按钮”插3个单选按钮。 <body> <form name=“form1” method=“POST” action=“control.php”> <input type=“radio” name=“rdb” value=“中国银行”>中国银行 <input type=“radio” name=“rdb” value=“工商银行”>工商银行 <input type=“radio” name=“rdb” value=“建设银行”>建设银行 </form> </body> 注:同一组单选按钮name值必须相同。rdb

  14. 7.4表单的单选按钮 打开Control.php输出用户选中的银行 <?php Echo “您选中的银行是:”.$_POST[“rdb”]; ?> 注:$_POST必须大写

  15. 7.5表单的列表菜单 单击“插入”|“表单”|“单选按钮”插3个单选按钮。 <body> <form name=“form1” method=“POST” action=“control.php”> <select name="slt"> <option value="北京">北京</option> <option value="上海">上海</option> <option value="天津">天津</option> <option value="重庆">重庆</option> </select> </form> </body> 注:同一组单选按钮name值必须相同。rdb

  16. 7.5表单的列表菜单 打开Control.php输出用户的出生地 <?php Echo “您的出生地是:”.$_POST[“slt”]; ?> 注:$_POST必须大写

More Related