如果您发现这个问题与任何其他问题相似,我很抱歉,但我已经检查过并且找不到合适的解决方案。我的登录检查脚本似乎有问题,因为即使我输入了错误的密码,它也会指向登录成功页面,但我找不到在哪里。请帮我。这是代码:
<?php
session_start();
mysql_connect("localhost", "root", "")or die("cannot connect");
mysql_select_db("planner")or die("cannot select DB");
$myusername = mysql_real_escape_string ($_POST['username']);
$mypassword = mysql_real_escape_string ($_POST['password']);
$sql="SELECT username,password FROM members WHERE username='$myusername'";
if($result=mysql_query($sql)){
$found_user=mysql_fetch_array($result);
if (mysql_num_rows($result)>0){
$_SESSION['myusername']=true;
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
}
?>
updated script:
<?php
session_start();
mysql_connect("localhost", "root", "")or die("cannot connect");
mysql_select_db("planner")or die("cannot select DB");
$myusername = mysql_real_escape_string ($_POST['username']);
$mypassword = md5(mysql_real_escape_string ($_POST['password']));
$sql="SELECT username,password FROM members WHERE username='$myusername' AND password='$mypassword'";
if($result=mysql_query($sql)){
$found_user=mysql_fetch_array($result);
if (mysql_num_rows($result)!=0){
$_SESSION['myusername']=true;
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
}
?>
now it always says wrong username and password entered even though
with right username and password entered. And here is the login form:
<form method="post" action="check_login.php">
<p><input type="text" name="username" value="" placeholder="Username"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<p class="submit"><input type="submit" name="submit" value="Login"></p>
</form>