User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,820 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,603 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Join Date: Apr 2008
Posts: 1
Reputation: qamarneo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
qamarneo qamarneo is offline Offline
Newbie Poster

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

  #42  
Apr 3rd, 2008
i got this error plz tell me what is main problem in code

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\login\checklogin.php on line 34
Wrong Username or Password
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Untitled Document</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. </head>
  7.  
  8. <body>
  9. <?php
  10. $host="localhost"; // Host name
  11. $username="root"; // Mysql username
  12. $password=""; // Mysql password
  13. $db_name="test"; // Database name
  14. $tbl_name="members"; // Table name
  15.  
  16. // Connect to server and select databse.
  17. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  18. mysql_select_db("$db_name")or die("cannot select DB");
  19.  
  20. // username and password sent from form
  21. $myusername=$_POST['myusername'];
  22. $mypassword=$_POST['mypassword'];
  23.  
  24. // To protect MySQL injection (more detail about MySQL injection)
  25. $myusername = stripslashes($myusername);
  26. $mypassword = stripslashes($mypassword);
  27. $myusername = mysql_real_escape_string($myusername);
  28. $mypassword = mysql_real_escape_string($mypassword);
  29.  
  30. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  31. $result=mysql_query($sql);
  32.  
  33. // Mysql_num_row is counting table row
  34. $count=mysql_num_rows($result);
  35. // If result matched $myusername and $mypassword, table row must be 1 row
  36.  
  37. if($count==1){
  38. // Register $myusername, $mypassword and redirect to file "login_success.php"
  39. session_register("myusername");
  40. session_register("mypassword");
  41. header("location:login_success.php");
  42. }
  43. else {
  44. echo "Wrong Username or Password";
  45. }
  46. ?>
  47.  
  48.  
  49. </body>
  50. </html>
Last edited by peter_budo : Apr 3rd, 2008 at 10:13 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
All times are GMT -4. The time now is 5:44 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC