我写了密码和用户名匹配的条件,它根据条件登录。但由于我是 PHP 新手,我不知道为什么它没有登录。
<html>
<head>
</head>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>
<?php
session_start();
if(isset($_POST['submit']))
{
include('connect.php');
// username and password sent from form
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
while($query4=mysql_fetch_array($result))
{
extract($query4);
$ul=$userlevel;
if ($ul=='A')
{
$_SESSION["username"]=$myusername;
$_SESSION["password"]=$mypassword;
header("location:projectmanager_main.php");
}
else if ($ul=='B')
{
$_SESSION["username"]=$myusername;
$_SESSION["password"]=$mypassword;
header("location:teamlead_main.php");
}
else if ($ul=='C')
{
$_SESSION["username"]=$myusername;
$_SESSION["password"]=$mypassword;
header("location:employees.php");
}
else
{
$_SESSION["username"]=$myusername;
$_SESSION["password"]=$mypassword;
header("location:admin_main.html");
}
}
}
else
{
echo "<p align='center'>"."<font color='red'>"."Wrong Username or Password. Please Try Again"."</font>"."</p>";
}
}
?>