登录不工作,注册时是

时间:2012-10-06 18:48:05

标签: php mysql login

我已经做了足够的研究,当登录它时,如果密码也正确,我没有将我重定向到资源页面。我之前尝试过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);
?>

1 个答案:

答案 0 :(得分:1)

你在回声之前遗漏了一个分号

mysql_query("INSERT INTO USERS(NAME,USERNAME,PASSWD) VALUES('$name','$usr','$passwd')");//<-- right here
echo "congrats! you have been added.Go back to resources and log in";

此外,您还没有清理用户输入,查看准备好的语句(PDOmysqli