[英]form if(isset($_POST['login'])) not working at all in php
[英]Using isset() method to vaidate login form. PHP
我试图创建此登录表单以在同一页面上进行验证。 登录验证后,它应该隐藏表单。 我一直在测试,但是没有显示任何错误。 当我单击提交按钮时,它将刷新页面。
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><?php
$DisplayForm = TRUE;
$errors = 0;
if(isset($_POST['loginForm'])){
include("dbconnect.php");
if($DBConnect !== FALSE){
$SQLstring = "SELECT userid, first_name, last_name FROM users WHERE username ='".
$_POST['uname']. "' and password = '".md5($_POST['pass'])."'";
$DisplayForm = FALSE;
$QueryResult = @mysql_query($SQLstring, $DBConnect);
echo mysql_error();
if (mysql_num_rows($QueryResult)=== 0){
echo "<p>The email address/password " .
" combination is not valid.</p>\n";
++$errors;
$DisplayForm = TRUE;
}
else
{
$DisplayForm = FALSE;
}
}
}
if ($DisplayForm)
{?>
<form id="form1" name="loginForm" method="post" action="index.php">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="93" bgcolor="#DACFAF"><strong> Username:</strong></td>
<td width="149" bgcolor="#DACFAF"><label for="textfield"></label>
<input type="text" name="uname" id="textfield" /></td>
<td width="76" bgcolor="#DACFAF"><strong>Password:</strong></td>
<td width="150" bgcolor="#DACFAF"><label for="textfield2"></label>
<input type="password" name="pass" id="pass" /></td>
<td width="196" bgcolor="#DACFAF"><input type="image" name="login" src="images/login.jpg" /> </td>
<td width="68" bgcolor="#DACFAF"> </td>
<td width="68" bgcolor="#DACFAF"><strong><a href="register.php">Register</a></strong> </td>
</tr>
</table>
</form>
<?php }
else {
$Row = mysql_fetch_assoc($QueryResult);
$userID = $Row['userid'];
$userName = $Row['first_name']. " ". $Row['last_name'];
echo "<p>Welcome back, $userName!</p>\n";
}
?> </td>
</tr>
</table>
您没有提交按钮。
将以下内容添加到您的表单中:
<input type="submit" name="formSubmit" />
然后,您可以签入第一个isset行: isset($_POST['uname'] && $_POST['pass']);
您无法在<form>
上应用isset。 尝试在输入字段上应用isset
<?php
if(isset($_POST['uname'] && isset($_POST['pass'])) {
// .. foo
}
?>
而且,您的表格永远不会提交。 添加<input type="submit" value="Register" />
要检查是否发布了某些内容,您应该添加一个隐藏的输入字段:
<input type="hidden" name="wasSubmitted" value="true">
然后检查isset($_POST['wasSubmitted'])
或$_POST['submitted'] == 'true'
。
$_POST[]
超全局变量中仅包含字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.