开发者

How do I check the return value of an SQL query in PHP?

So if I have the code:

$result = mysql_query("SELECT password FROM users WHERE username = '$username'");
$return = mysql_fetch_assoc($result);

I then want to check the returned value, namely, the value of "password". Therefore, I tried this:

开发者_StackOverflow中文版if ($return['password'] == $password)
{
    login_success();
}

However, that code just puts PHP into some sort of crazy loop mode where it prints out the page content again and again endlessly until I close my browser. So how do I check the return value of password against the text stored in the variable password?


For check login purpose follow below code

  $username=$_REQUEST['username'];
$password=$_REQUEST['password'];

$query="select * from users where username='$username' and password='$password' ";

$result=mysql_num_rows(mysql_query($query));

if($result>0)
{
     echo "Login Success";           
}
else
{
    echo "Login Failed";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜