我有一个这样的基本形式:
<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。
答案 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"]." ";
}
在表单上成功获取并输出您的输入。希望这会对你有所帮助