php学习练手(一)

学习目的

将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方式传递的数据,安全性较高。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值