php $ _POST总是空的

时间:2017-05-31 15:41:08

标签: php html

我正在尝试用PHP和HTML制作一个示例寄存器表单。

我有HTML页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Register</title>
</head>
<body>
    </br></br></br></br>
    <form method="post" action="register.php">
        <label>Username:</label>
        <input type="text" id="uname" name="uname" placeholder="insert username" required></input></br>
        <label>Password:</label>
        <input type="password" id="pwd" name="pwd" placeholder="insert password" required></input></br>
        <label>Retype Password:</label>
        <input type="password" id="cpwd" name="cpwd" placeholder="confirm password" required></input></br>

        <input type="submit" name="submit" value="Registrami"></input>
    </form>
</body>
</html>

以及被调用的PHP操作:

<?php
$username="def";
$password="def";
if(isset($_POST['submit'])) {
    if (isset($_POST['uname'])) {
        echo "yes";
        $username = $_POST['uname'];
    } else {
        echo "no";
    }
    if (!empty($_POST['pwd'])) {
        $password = $_POST['pwd'];
    }
    if (!empty($_POST['cpwd'])) {
        $cpassword = $_POST['cpwd'];
    }
}
echo $username;
echo $password;
require('connection.php');
?>

$ _POST中没有任何内容传递。当我尝试分配$username=$_POST['uname']时,它不会更改值。 我也试过使用$_REQUEST. 有任何想法吗? 感谢您对此事感兴趣!

1 个答案:

答案 0 :(得分:0)

以前的用户是对的,我想给他信用,但他删除了答案。所以我只是重新发布他的建议:

$post_data = file_get_contents("php://input"); //getting post like this  `