[英]HTML form not passing values to PHP script on localhost, wamp server
I have a WAMP server setup and I have the following form in file login.php 我有一个WAMP服务器设置,文件login.php中有以下表格
<form action="login.php" method="post">
Username: <input type="text" id="loginUsername" />
Password: <input type="password" id="loginPassword" />
<input type="submit" value="Log-in" id="login" />
</form>
And in the same file I have this PHP: 在同一文件中,我有以下PHP:
if(isset($_POST))
{
print "post is set";
print_r($_POST);
}
However the print_r() never displays any of the field's values. 但是,print_r()永远不会显示该字段的任何值。 I have tried using the get method in the form too.
我也尝试过在表单中使用get方法。
Is this something to do with hosting on WAMP? 这与在WAMP上托管有关吗?
You forgot the name
attributes for your form elements. 您忘记了表单元素的
name
属性。 Without it those values will not be submitted. 没有它,这些值将不会提交。
<form action="login.php" method="post">
Username: <input type="text" name="loginUsername" id="loginUsername" />
Password: <input type="password" name="loginPassword" id="loginPassword" />
<input type="submit" value="Log-in" id="login" /></p>
</form>
you must provide name attribute for the input element so that they can be available in the global variable $_GET ,$_POST or $_REQUEST. 您必须为输入元素提供name属性,以便它们可以在全局变量$ _GET,$ _ POST或$ _REQUEST中使用。 Remember id or class ,etc are for javascript/jquery/css processing and name attribute are server side processing (php ,jsp ,etc)
记住id或class等用于javascript / jquery / css处理,而name属性是服务器端处理(php,jsp等)
<form action="login.php" method="post">
<label for="username">Username:</label><input type="text" name="username" id="username" />
<label for="password">Password:</label> <input type="password" name ="password"id="password" />
<input type="submit" value="Log-in" id="login" />
</form>
hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.