469,925 Members | 1,519 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,925 developers. It's quick & easy.

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

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
5 2063
Markus
6,050 Expert 4TB
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
5,058 Expert 4TB
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
Mubs
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
Mubs
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
6,050 Expert 4TB
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.

Similar topics

3 posts views Thread by Klaus Hansen | last post: by
1 post views Thread by nkosinathi | last post: by
10 posts views Thread by Caffeneide | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.