我已经做了足够的研究,当登录它时,如果密码也正确,我没有将我重定向到资源页面。我之前尝试过SHA1密码但是先处理更简单的情况,我将其删除了。 当我问NAME ='$ usr'时, 因为我有用户名, 如果我也输入用户,它会显示错误的用户名,在终端上如果我们尝试这个,对于用户名'用户'或'用户',它显示相同的事情。
<?php
$con = mysql_connect("localhost","root","*****");
session_start();
if(isset($_POST['submit1']))
{
if (!$con)
{
die("OOPS!Could not connect to server".mysql_error());
}
$passwd = $_POST['password'];
$usr=$_POST['username'];
mysql_select_db('USERS',$con) or die(mysql_error());
$result = mysql_query("SELECT PASSWD FROM USERS WHERE USERNAME='$usr'",$con) Or die(mysql_error());
$pass = mysql_result($result,0);
if ($pass==$passwd) {
header('Location : resource.html');}
else
{echo "sorry $usr wrong username or password"; }
}
else if(isset($_POST['submit2']))
{
$usr = $_POST['user'];
$passwd = $_POST['password1'];
$name = $_POST['fullname'];
mysql_select_db('USERS',$con) or die(mysql_error());
$result = mysql_query("SELECT * FROM USERS WHERE USERNAME='$usr'",$con) Or die(mysql_error());
$num = mysql_num_rows($result);
if ($num==0) {
mysql_query("INSERT INTO USERS(NAME,USERNAME,PASSWD) VALUES('$name','$usr','$passwd')");
echo "congrats! you have been added.Go back to resources and log in";
}
else echo "Someone already has that username. Go back and try with another username";
}
mysql_close($con);
?>