Author Topic: Login Script! Help!!!  (Read 2680 times)

seenu

  • New Member
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Login Script! Help!!!
« on: April 26, 2004, 04:12:15 PM »
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!";
}

---------------------------------------

Tarential

  • Regular Member
  • **
  • Posts: 94
  • Karma: 0
    • View Profile
(No subject)
« Reply #1 on: April 26, 2004, 05:21:33 PM »
Try substituting:
Code: [Select]
if ($num == "0" || $num == NULL) //login failed
{
include('Warehouse_login.htm');
exit;

}

else
{
echo "Logged in Successfully!";
}


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).
"I did not sleep with those medals... er, throw away those weapons of mass destruction... I mean ribbons... what was the question again?" - US Presidents 101
------
Disclaimer: Don't bother messaging me about this. You'll just start a flame war.

ManiacalV

  • Regular Member
  • **
  • Posts: 40
  • Karma: 0
    • View Profile
(No subject)
« Reply #2 on: April 27, 2004, 04:21:28 PM »
Wouldn't
Code: [Select]
if (empty($num)) //login failed
be the same as
Code: [Select]
if ($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.

drewbee

  • Regular Member
  • **
  • Posts: 38
  • Karma: 0
    • View Profile
(No subject)
« Reply #3 on: April 27, 2004, 09:08:07 PM »
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...
Rather then be like most men who want the world to know them; I want to know the world.

Tarential

  • Regular Member
  • **
  • Posts: 94
  • Karma: 0
    • View Profile
(No subject)
« Reply #4 on: April 27, 2004, 11:20:39 PM »
Quote from: "ManiacalV"
Since empty($variable) will return TRUE if  $variable is "", 0, "0", NULL, FALSE, array(), var $var;, or an object with empty properties.


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.
"I did not sleep with those medals... er, throw away those weapons of mass destruction... I mean ribbons... what was the question again?" - US Presidents 101
------
Disclaimer: Don't bother messaging me about this. You'll just start a flame war.