Login Script! Help!!!

Hi,
I am a newbie with PHP/MySQL.I am trying to work on a Login Script for a while.It is not going to else part even with a valid user?
Any help please?

---------------------------Login Script-------------------------------------

$db = mysql_connect(“localhost”, “root”, “”);
mysql_select_db(“podb”,$db);
$result = mysql_query(“SELECT * FROM users WHERE
user= ‘user’ AND pass= ‘pass’”,$db)
or die(“Couldn’t query the user-database.”);

$num = mysql_num_rows($result);

if ($num == “0”) //login failed
{
include(‘Warehouse_login.htm’);
exit;

}

else
{
echo “Logged in Successfully!”;
}


Try substituting:

[code]if ($num == “0” || $num == NULL) //login failed
{
include(‘Warehouse_login.htm’);
exit;

}

else
{
echo “Logged in Successfully!”;
}[/code]

Your code looks good, though. I don’t think what I added will fix it. Seems to me more likely to check your query against the database itself - that is to say, copy and paste the query into phpmyadmin or in the local mysql client. See what results come up. (By this, of course, I mean to echo the query of what you THINK should be a working username/pass and check that).

Wouldn’t

if (empty($num)) //login failed be the same asif ($num == "0" || $num == NULL) //login failed
Since empty($variable) will return TRUE if $variable is “”, 0, “0”, NULL, FALSE, array(), var $var;, or an object with empty properties.

Yeah Maniac, atleast thats how they describe it on the description… He did say that he was pretty sure that would not fix it though, and it rather be the database checking…

Mayhap so, but as the case may be, I noted a comment in the PHP.net manual where someone told how to check if a var was empty. He said the only way to truly check was to check in multiple ways. Maybe there is something buggy with the PHP checking, maybe he is just wrong. Either way, as I mentioned, I did not expect it to work.

Sponsor our Newsletter | Privacy Policy | Terms of Service