[英]PHP form data not being POSTED
I created a form which asks for username and password for registration purposes and I sent the data to same page using action=""
and checking for $_POST
variables, but data is not being passed through this method. 我创建了一个表单,该表单要求注册时使用用户名和密码,然后使用action=""
将数据发送到同一页面并检查$_POST
变量,但是没有通过此方法传递数据。 When I print $POST
array by changing condition to true and reloading the page , the POST
array is empty and also I can see the variables passed as POST
in URL.Can somebody explain whats the problem? 当我通过将条件更改为true并重新加载页面来打印$POST
数组时, POST
数组为空,我也可以看到URL中以POST
形式传递的变量。有人可以解释什么问题吗
Code: 码:
<!DOCTYPE html>
<html>
<?php
if(isset($_POST['user']))
{
echo "Data coming";
die();
}
else {
?>
<form method="POST" enctype="multiform/form-data" action="">
<b> Username: </b><input type='text' name='user'> <br> <br><br>
<b> Password:</b> <input type='password' name='pass'><br> <br>
<input type='submit' value="Submit">
</form>
<?php
}
?>
</html>
You have to give the name to submit button also. 您还必须提供名称以提交按钮。
<input type='submit' name="Submit" value="Submit">
You are checking the index 'Submit' in $_POST
and the submitted form is take the value with the name of input type. 您正在$_POST
中检查索引“ Submit” ,并且提交的表单采用带有输入类型名称的值。 So you have to given the name to submit button also like above. 因此,您也必须像上面一样给名称提交按钮。
You are checking in your if isset for a post named: $_POST['Submit'] 您正在检查ifset中是否有名为$ _POST ['Submit']的帖子
Your submit button doesn't have name=Submit 您的提交按钮没有名称=提交
As a test to see what you are sending for debug purposes, try putting this in your code, it will help you self-debug: 为了测试您发送的调试信息,请尝试将其放入代码中,这将有助于您进行自我调试:
print_r($_REQUEST);
“ input type ='submit'name =” Submit“ ...更改为此。$ _POST ['Submit']在重新加载页面时查找名称为Submit的资源,因为在您的代码中没有资源提交名称,if语句返回false,然后控制切换回else部分,为Submit按钮指定一个名称,并在varibale选项中使用相同的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.