By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,363 Members | 3,622 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,363 IT Pros & Developers. It's quick & easy.

PHP MySQL error: supplied argument is not a valid MySQL result resource

P: 77
Hi,

I 'am trying to connect my sql database with my webpage for users log in. i have got this script so far but i keep getting the following error message which i cannot figure out..

could any1 help..
Expand|Select|Wrap|Line Numbers
  1. error:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\checklogin.php on line 18
  2. Wrong Username or Password
  3.  
code:
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. $hostname_mysql_connect = "localhost";
  4. $database_mysql_connect = "website_members";
  5. $username_mysql_connect = "root";
  6. $password_mysql_connect = "******";
  7. $tblname_mysql_connect ="members";
  8.  
  9. $mysql_connect = mysql_pconnect($hostname_mysql_connect, $username_mysql_connect, $password_mysql_connect, $tblname_mysql_connect) or trigger_error(mysql_error(),E_USER_ERROR); 
  10. mysql_select_db($database_mysql_connect) or die(mysql_error());
  11.  
  12. $myusername = $_POST['myusername'];
  13. $mypassword = $_POST['mypassword'];
  14.  
  15. $sql = "SELECT * FROM $tblname_mysql_connect WHERE username= '$myusername' and password='$mypassword'"; 
  16. $result = mysql_query($sql);
  17.  
  18. $count = mysql_num_rows($result); (line 18)
  19. if($count==1) {
  20.  session_register("myusername");
  21.  session_register("mypassword");
  22.  header("location:login_success.php");
  23.  }
  24.  else {
  25.  echo "Wrong Username or Password";
  26.  }
  27.  
  28. ?>
  29.  
many thanx
Jun 25 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
On your mysql query add: or die(mysql_error())

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query($sql) or die(mysql_error());
  2.  
At a glance I can't see the problem. Maybe this will give a help.
Jun 25 '08 #2

Atli
Expert 5K+
P: 5,058
Hi.

Please use [code] tags when posting your code examples. (See How to ask a question)

[code=php] ...PHP code goes here... [/code]

I've also changed the title of the thread to better describe it's contents.

Thank you.
Jun 26 '08 #3

P: 77
On your mysql query add: or die(mysql_error())

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query($sql) or die(mysql_error());
  2.  
At a glance I can't see the problem. Maybe this will give a help.

HI... I tried the following code and i got this for an error:

Unknown column 'password' in 'where clause'
Jun 26 '08 #4

P: 77
HI... I tried the following code and i got this for an error:

Unknown column 'password' in 'where clause'

I just figured it out...i mis spelt the password field..

many thanx for all posts..
Jun 26 '08 #5

Markus
Expert 5K+
P: 6,050
I just figured it out...i mis spelt the password field..

many thanx for all posts..
Thought it would help.

Remember to use those 'or die(mysql_error())' on your mysql queries!
Jun 26 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.