473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

login only works on localhost

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
1 1536
AutumnsDecay
170 100+
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

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

Similar topics

3
by: Jim Peter | last post by:
Hello , this is my first posting in this group. I am running SQL server 2000 on my windows 2000 server box. I use it for my Siebel database. When ever I launch Query Analyzer and chose SQL Server...
0
by: VB Programmer | last post by:
This is a asp.net 2.0 website. I just deployed the members-only pages. When I log in on my dev machine everything works perfectly. When I try to login on the website I get "Your login attempt was...
0
by: Vince | last post by:
I installed IE7 and later had to uninstall it. Now when I open Visual Studio projects I am prompted for my login credentials. Previously it just opened the projects without prompting. It prompts...
4
by: =?Utf-8?B?S2lyYW4gS3VtYXIgUGluamFsYQ==?= | last post by:
Hi, I have an SSL Web site that is developed and deployed using in .NET 2.0. Most of the clients are able to login to my website without any issues. Some clients can never login to my web site. At...
2
by: Jeppe Jespersen | last post by:
I have built and deployed a site that uses Membership and Role providers. The site has a SiteMap and a Menu control thats security trimmed. a) When I'm on the webserver, and attempt to log on (to...
14
victorduwon
by: victorduwon | last post by:
Hi guys and gals, I am using javascript to autologin to my google analytics account via a hyperlink. This is what the text looks like this <?xml version="1.0" encoding="utf-8"?>...
7
by: pek | last post by:
OK, I've been having this problem for quite some time but never until now I really needed a solution. I have never thought of a work around, so I really need your help. Sorry if this has been...
0
by: Uwe | last post by:
Hi, I'm currently developing an ASP.NET application with my own MembershipProvider. Login works fine on my local machine (IIS7) in a virtual directory of IIS. I just deployed the application to a...
3
by: liz0001 | last post by:
I am developing a mobile version of my site. I have limited testing resources: a Blackberry and Kindle. I have a friend who can run a test on an iPhone, but I don't have access to it. The...
4
matheussousuke
by: matheussousuke | last post by:
Hi, I have just uploaded a website to server, it's working fine, at least for one thing, if login to it on my computer (localhost) the login works fine, but if I do the same on webserver, it doesn't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.