我如何使用PHP表单?

时间:2014-10-19 23:36:34

标签: php forms web parameters

我在我的网络服务器上有这个支持php的php文件。

$ Content = $ _POST ['内容'];

echo $ Content;

当我打开名为put.php的文件时,put.php?Content = 200没有任何反应。

也许你们中的任何人都可以帮助我。我已经读过它运行的是html文件,其中用户填写信息并按下按钮发送它,但我只想打开带有指定信息的php文件。

提前致谢。

2 个答案:

答案 0 :(得分:1)

在PHP中,$_POST指的是由表单提交

设置的变量

$_GET用于获取查询字符串参数,即put.php?Content=200;

echo $_GET['Content'];

请注意,直接回显$_GET$_POST可能会使您的网站被用于XSS攻击。

答案 1 :(得分:1)

以下是POST表单的示例。正如Machavity告诉你的那样,以这种方式做到这一点是不安全的,但它会教你基础知识。我在里面写了一些评论,它会告诉你究竟做了什么。

<?php

/*
First we'll make an if statement that checks if there's actually
a username set. In here you'll see "isset". This checks if the POST
variable 'username' exists. Secondly you see "empty". This will
check if the variable is empty. Ofcourse we don't want it to be
empty, so we'll put a ! in front of it. This makes it do exact opposite
and check if it's NOT empty.
*/
if(isset($_POST['username']) && !empty($_POST['username'])){
    //Here we'll echo a message to the user with his username and
    //2 returns so the form is a little bit further down.
    echo "Hello, " . $_POST['username'] . "<br /><br />";
}

//With this we can even give the user a message when he tries to
//sumit the form without entering a username at all.
if(empty($_POST['username'])){
    echo "You did not enter a username! <br /><br />";
}

?>

<!DOCTYPE HTML>
<html>
    <head>
        <title>Please enter your username</title>
    </head>
    <body>
        <!-- With method set to post, we're telling the form that we're using POST and not GET -->
        <!-- You should save this file as "example.php" as we're telling it to send the form data -->
        <!-- towards example.php. -->
        <form method="post" action="example.php" accept-charset="utf-8">
            Please enter your username: <input type="text" name="username" /><br />
            <input type="submit" value="Send" />
        </form>
    </body>
</html>