php学习练手(一)

来源:互联网 发布:婚纱照一键修图软件 编辑:程序博客网 时间:2024/05/17 22:13

学习目的

将form.php中html内form表单内容提交到handle_form.php中,最终显示出来。


代码

form.php:

<?php?><!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><style type="text/css" title="text/css" media="all">    label{font-weight: bold; color: #300ACC;}</style><body><!--Script 2.1 -form.html-->    <form action="handle_form.php" method="post">        <fieldset>            <legend>Enter your information in the form below:</legend>            <p><label>Name:<input type="text" name="name" class="name" /></label></p>            <p><label>Email Adress: <input type="text" name="email" class="email" /></label></p>            <p>Gender:<input type="radio" name="gender" id="M" /><label for="male">Male</label><input type="radio" name="gender" id="F" /><label for="female">Female</label></p>            <p><label>Age:<select>                <option value="0-29">Under 30</option>                <option value="30-60">Between 30 and 60</option>                <option value="60+">Over 60</option>            </select></label></p>            <p><label>Comments: <textarea name="comments" rows="3" cols="40"></textarea></label></p>        </fieldset>        <p align="center"><input type="submit" name="submit" value="Submit My Information" /></p>    </form></body></html>

handle_form.php:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><body>    <?php #Script 2.2 - handle_form.php        $name = $_REQUEST['name'];        $email = $_REQUEST['email'];        $comments = $_REQUEST['comments'];        echo "<p>Thank you, <b>$name</b>,for the following comments:<br/>                    <tt>$comments</tt></p>                    <p>We reply to you at <i>$email</i></p>";    ?></body></html>

结果

form.php:
这里写图片描述
handle_form.php:
这里写图片描述

知识点总结

  • 重要html标签:fieldset,select

  • php超全局变量:$_REQUEST——它存储了通过GET或POST方式发送到php页面的所有数据,以及在cookie中可访问的数据。与 $_GET方式或$_POST相比,其速度较慢。$_GET方式获取浏览器的GET方式传递的数据,在url中可见,安全性差,且数据传送量小,不大于2kB。$_POST方式获取浏览器通过POST方式传递的数据,安全性较高。

0 0