$_POST 或$_GET或 $_REQUEST接受表单值

来源:互联网 发布:网络摄像头有看头下载 编辑:程序博客网 时间:2024/06/07 00:59

//就这么个问题困扰我好久, 我用$_get, or $_post or $_request, 都接收不到表单传来的值
HTML代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1 align="center"><img src="u=3289850893,3856207640&fm=21&gp=0.jpg">
    Certification<img src="u=3289850893,3856207640&fm=21&gp=0.jpg"></h1>
<p>You too can earn your highly respected PHP certification
    from the world famous Fictional Institute of PHP Certification</p>
<p>Simply answer the questions below:</p>
<form action="score.php" method="post">
    <p>Your Name <input type="text" name="name"></p>
    <p>What does the PHP statement echo do?</p>
    <ul>
        <li><input type="radio" name="q1" value="1"> Outputs strings.</li>
        <li><input type="radio" name="q1" value="2">Adds two numbers together.</li>
        <li><input type="radio" name="q1" value="3">Creates a magical elf to finish writing your code</li>
    </ul>
    <p>What does the PHP function cos()do?</p>
    <ul>
        <li><input type="radio" name="q2" value="1">Calculates a cosine in radians.</li>
        <li><input type="radio" name="q2" value="2">Calculates a tangent in radians.</li>
        <li><input type="radio" name="q2" value="3">It is not a PHP function, It is a lettuce.</li>
    </ul>
    <P>What does the PHP function mail()do?</P>
    <ul>
        <li><input type="radio" name="q3" value="1">Sends a mail message.
        <li><input type="radio" name="q3" value="2">Checks for new mail.
        <li><input type="radio" name="q3" value="3">Toggle PHP between male and female mode.
    </ul>
    <p align="center"><input type="image" src="u=3919487505,3470538747&fm=15&gp=1.jpg" border="0"></p>
</form>
</body>
</html>

//php 代码 

<?php
//create short variable names
$name=$_GET['name'];
var_dump($name);  //返回都是 null, 
$q1=$_GET['q1'];
$q2=$_GET['q2'];
$q3=$_REQUEST['q3'];

//check that all the data was received
if (($q1=='')||($q2=='')||($q3=='')||($name=='')){
    echo "<h1><p align='center'>
            <img src='u=3289850893,3856207640&fm=21&gp=0.jpg' alt=''>
            Sorry:
            <img src='u=3289850893,3856207640&fm=21&gp=0.jpg' alt=''>
          </p></h1>
          <p>You need to fill in your name and answer all questions.</p>";
//最终都是没有接受到,返回You need to fill in your name and answer all questions


0 0