2 Replies - 880 Views - Last Post: 25 March 2011 - 04:59 PM Rate Topic: -----

#1 Lyonheart14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-March 11

php login authentication: query result checking

Posted 25 March 2011 - 01:30 PM

This is code for some basic php/mysql login authentication, I pass in the username and password to the file(not shown), connect(connect data not shown), and i am getting an error that mysql_num_rows expects parameter 1 to be a resource, could someone explain this to me? I have tried using the statement if(!(mysql_num_rows($result)))" instead of the current comparison. Also, could someone let me know if the echos that have will actually let me know if I am connected and accessing the database instead of just printing no matter what?


mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not connect".mysql_error());
echo "Connected to Server<br />";

mysql_select_db($dbname) or die("Could not open database".mysql_error());
echo "Connected to Database<br />";

$username = mysql_real_escape_string($username);
$query = "SELECT password FROM BiorhythmUsers WHERE username = '$username';<br />";
echo "$query<br />";

$result = mysql_query($query);
if(mysql_num_rows($result) < 1)
        die("No such User");

$userData = mysql_fetch_array($result, MYSQL_ASSOC);
if($password != $userData['password'])
        die("Incorrect Password");

$name = $userData['username'];
$bday = $userData['birthdate'];


This post has been edited by Lyonheart14: 25 March 2011 - 01:31 PM


Is This A Good Question/Topic? 0
  • +

Replies To: php login authentication: query result checking

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,437
  • Joined: 23-August 08

Re: php login authentication: query result checking

Posted 25 March 2011 - 02:08 PM

$result = mysql_query($query) or die("Query $query failed: " . mysql_error());

Was This Post Helpful? 0
  • +
  • -

#3 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: php login authentication: query result checking

Posted 25 March 2011 - 04:59 PM

Why is ;<br /> in your query? PHP throws the invalid resource error because your query returned an error.

Fixed:
$query = "SELECT password FROM BiorhythmUsers WHERE username = '$username'";

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1