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

login only works on localhost

P: 1
im just starting to learn php. im working on a basic login/user registration form and it works fine on localhost, but after i uploaded it to my server i get this error messag when i input correct login info:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Hosting\8927368\html\EKMN\login.php on line 53
The username you entered was not found.

here is my code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. error_reporting (E_ALL ^ E_NOTICE);
  3. session_start();
  4. $userid = $_SESSION['userid'];
  5. $username = $_SESSION['username'];
  6. ?>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  11. <title>username Login</title>
  12. </head>
  13. <body>
  14.     <?php
  15.  
  16.     if($username && $userid){
  17.         echo "Hey <b>$username</b>, you're already logged in! <a href='./member.php'>click here</a> for member page";
  18.  
  19.     }
  20.     else{
  21.         $form = "<form action='./login.php' method='POST'>
  22.         <table>
  23.         <tr>
  24.             <td>Username</td>
  25.             <td><input type='text' name='username' /></td>
  26.         </tr>
  27.         <tr>
  28.             <td>Password</td>
  29.             <td><input type='password' name='password' /></td>
  30.         </tr>
  31.         <tr>
  32.             <td></td>
  33.             <td><input type='submit' name='loginbtn'          value='login' /></td>
  34.         </tr>
  35.         <tr>
  36.             <td><a href='./register.php'>Register</a></td>
  37.             <td><a href='./forgotpass.php'>Forgot your password?</a></td>
  38.         </tr>
  39.         </table>
  40.         </form>";
  41.  
  42.         if ($_POST['loginbtn']){
  43.             $username = $_POST ['username'];
  44.             $password = $_POST['password'];
  45.  
  46.             if ($username){
  47.                 if($password){
  48.                     require("connect.php");
  49.  
  50.                     $password = md5(md5("nt4ui2t".$password."gj4h3h"));
  51.                     // make sure login info is correct
  52.                     $query = mysql_query("SELECT * FROM users WHERE username='$username'");
  53.                     $numrows = mysql_num_rows($query);
  54.                     if ($numrows == 1){
  55.                         $row = mysql_fetch_assoc($query);
  56.                         $dbid = $row['userid'];
  57.                         $dbuser = $row['username'];
  58.                         $dbpass = $row['password'];
  59.                         $dbactive = $row['active'];
  60.  
  61.                         if($password == $dbpass){
  62.                             if($dbactive == 1){
  63.                                 // set session info
  64.                                 $_SESSION['userid'] = $dbid;
  65.                                 $_SESSION['username'] = $dbuser;
  66.  
  67.                                 echo "Hey <b>$dbid</b> <a href='./member.php'>click here</a> for member page";
  68.                                 echo "<br />";
  69.                                 echo "userid: ".$_SESSION['userid'];
  70.                             }
  71.                             else
  72.                                 echo "You must activate your account before logging in.";
  73.                         }
  74.                         else
  75.                             echo "Wrong password!";
  76.  
  77.                     }
  78.                     else
  79.                         echo "The username you entered was not found. $form";
  80.                     mysql_close();
  81.                 }
  82.                 else
  83.                     echo "You forgot your password! $form";
  84.             }
  85.             else
  86.                 echo "You forgot your username! $form";
  87.         }
  88.         else
  89.             echo $form;
  90.     }    
  91.     ?> 
  92.  
  93.  
  94. </body>
  95. </html>
  96.  
Apr 30 '12 #1
Share this Question
Share on Google+
1 Reply


AutumnsDecay
100+
P: 170
A shot in the dark, but did you remember to set which database to use in your 'connect.php' file?

If you have more than one database running on your hosted server it could be confused.

If you didn't, try adding:
Expand|Select|Wrap|Line Numbers
  1. mysql_select_db('YourDB');
before your query.
Apr 30 '12 #2

Post your reply

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