$ _POST变量不包含任何数据

时间:2017-05-23 17:31:52

标签: php forms post

我有一个这样的基本形式:

<form method="post" action="register.php" class="form">
    <input id="a" type="text" placeholder="Cod acces" name="access-code" size="20" required /><br>
    <input id="b" type="password" placeholder="Parola" name="password" autocomplete="new-password" size="20" required /><br>
    <input id="c" type="password" placeholder="Confirma parola" name="re-password" autocomplete="new-password" size="20" required /> <br><br>
    <input type="submit" value="Register" name="register" />
</form>

在register.php中,我有以下3行代码:

$password = $_POST["password"];
$repassword = $_POST["re-password"];
$acces_code = $_POST["access-code"];

即使此代码看起来很简单,我的$_POST变量也是空的。甚至更奇怪,如果我按F12查看请求数据,所有变量及其值都在那里。 我在Windows上使用XAMPP。

1 个答案:

答案 0 :(得分:-1)

以下是Windows版本10和Xampp Server的代码。

index.php粘贴以下代码

<html>
<body>
<form method="post" action="register.php" class="form">
    <input id="a" type="text" placeholder="Cod acces" name="access-code" size="20" required /><br>
    <input id="b" type="password" placeholder="Parola" name="password" autocomplete="new-password" size="20" required /><br>
    <input id="c" type="password" placeholder="Confirma parola" name="re-password" autocomplete="new-password" size="20" required /> <br><br>
    <input type="submit" value="Register" name="register" />
</form>
</body>
</html>

然后在register.php粘贴此代码

<?php
if(isset($_POST['register'])){

echo $password = $_POST["password"]." ";
echo $repassword = $_POST["re-password"]." ";
echo $acces_code = $_POST["access-code"]." ";

}

在表单上成功获取并输出您的输入。希望这会对你有所帮助