无法登入

时间:2011-03-13 01:20:28

标签: php login

的login.php

    // Create query
  $q = "SELECT * FROM `dbUsers` "
        ."WHERE `username`='".$_POST["username"]."' "
        ."AND `password`=PASSWORD('".$_POST["password"]."') "
        ."LIMIT 1";
  // Run query
  $r = mysql_query($q);

  if ( $obj = @mysql_fetch_object($r) )
        {
        // Login good, create session variables
        $_SESSION["valid_id"] = $obj->id;
        $_SESSION["valid_user"] = $_POST["username"];
        $_SESSION["valid_time"] = time();

        // Redirect to member page
        Header("Location: members.php");
        }
  else
        {
        // Login not successful
        die("Sorry, could not log you in. Wrong login information.");
        }
  }
        else
  {
//If all went right the Web form appears and users can log in
  echo "<form action=\"?op=login\" method=\"POST\">";
  echo "Username: <input name=\"username\" size=\"15\"><br />";
  echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
  echo "<input type=\"submit\" value=\"Login\">";
  echo "</form>";
  }
        ?>

无法使用上述代码登录。 if时出错($ obj = @mysql_fetch_object($ r)) 上述代码的错误消息:可能的意外分配,应避免条件分配

1 个答案:

答案 0 :(得分:0)

最后else与if / else严重嵌套。还有两个,只有一个if