Connect with Expertise | Find Experts, Get Answers, Share Insights

PHP login script displays blank

 
Join Date: Feb 2010
Posts: 12
#1: Feb 9 '10
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include("connect.php");
  4. include("dbaselevel.php");
  5.  
  6. session_start();
  7.  
  8.     $username = $_POST['username'];
  9.     $password = $_POST['password'];
  10.  
  11.         if ($username&&$password)
  12.         { 
  13.             echo("checking username and password");
  14.             $open_data = connect_dbase("login");
  15.  
  16.             $query = mysql_query("SELECT * FROM users WHERE userid = '$username'");        
  17.             $rows = mysql_numrows($query);
  18.  
  19.             echo($rows);
  20.  
  21.             if ($rows!=0)
  22.             {
  23.                 while ($dbrows = mysql_fetch_assoc($query)) 
  24.                 {
  25.                     $dbusername = $dbrows['userid'];
  26.                     $dbpassword = $dbrows['password'];
  27.                 }
  28.                 if ($username==$dbusername&&$password==$dbpassword)
  29.                 {
  30.                     $_session['username']=$username;
  31.                     $dblevel = mysql_query("SELECT 'level' FROM users WHERE userid = '$username'");
  32.                     $return_level = dbase_level_check($dblevel);
  33.                     $echo ($username. "you're in at". $dblevel);
  34.                     //header("location: {$return_level}");
  35.                     exit();
  36.                 }
  37.                 else 
  38.                      die("incorrect login information");    
  39.             }
  40.             else 
  41.                 die("Username does not exist!");
  42.         }
  43.         else
  44.             die("Please enter Username and Password");
  45. ?>
I am building a database driven website, and this is the login.php file that I have written to access a users database.

it dies as soon as it checks to see if the user's name and password are correct. I am using a directory structure on my server (SME 7.4) that looks like this

HTML/includes

the includes directory holds all of my PHP files and is called from my index.html file through a simple HTML login form. The login form calls login.php, and the address bar, in the browser, shows that it is at least looking for the file, but no output.

I am stumped.
best answer - posted by Phill
Expand|Select|Wrap|Line Numbers
  1.  $open_data = connect_dbase("login");
  2.  
Don't understand why you have this. Wouldn't it just be:

Expand|Select|Wrap|Line Numbers
  1. connect_dbase("login");
  2.  
OR put your sql as:

Expand|Select|Wrap|Line Numbers
  1. $query = mysql_query("SELECT * FROM users WHERE userid = '$username'", $open_data);        
  2.             $rows = mysql_numrows($query);
  3.  
mmm

Atli's Avatar
E
M
C
 
Join Date: Nov 2006
Location: Iceland
Posts: 4,618
#2: Feb 9 '10

re: PHP login script displays blank


Hey.

Does it stop before the echo on line #13?
And do you have error messages turned on?

Also, consider what would happen if I were to pass this as my username:
Expand|Select|Wrap|Line Numbers
  1. ' OR 1='1
See what would happen to your SQL query?
You should read up on SQL Injection and check out the mysql_real_escape_string function. (The most important thing you will learn about PHP development!)
 
Join Date: Feb 2010
Posts: 12
#3: Feb 9 '10

re: PHP login script displays blank


I get a blank screen with the browser pointing at the login.php file
 
Join Date: Feb 2010
Posts: 12
#4: Feb 9 '10

re: PHP login script displays blank


I just read up on the escape characters.. . . . yikes

anyways Thank you very much. I have changed the code a bit to reflect mysql_real_escape_string that is a huge hole in my code. . . .
Atli's Avatar
E
M
C
 
Join Date: Nov 2006
Location: Iceland
Posts: 4,618
#5: Feb 9 '10

re: PHP login script displays blank


Ok, so you aren't getting any errors, even though you have turned on the error messages?

How exactly does your connect_dbase function look like? Could the error be there?

There is at least nothing in that code that would explain this, so the problem must be in the code you have included into this script.
 
Join Date: Feb 2010
Posts: 12
#6: Feb 10 '10

re: PHP login script displays blank


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // connect to the database needed
  3.  
  4. function connect_dbase($DBase)
  5. {
  6.     echo("connecting to data");
  7.     if ($DBase == "login")
  8.     {
  9.         $DB= "XXXXXX";
  10.         $uname= "apid";
  11.         $pword= "xxxxxx";
  12.         echo("user login");
  13.     }
  14.     else if ($DBase == "users")
  15.     {
  16.         $DB= "XXXXXXX";
  17.         $uname= "level1";
  18.         $pword= "xxxxx";
  19.         echo("user database entry");
  20.     }    
  21.     else if ($DBase == "animal")
  22.     {
  23.         $DB= "XXXXXXX";
  24.         $uname= "level1";
  25.         $pword= "xxxxxx";
  26.     }        
  27.     $connection = mysql_connect("localhost:3306",$uname,$pword) or die("could not connect to the database");
  28.     mysql_select_db($DB);
  29.     echo ("your connected ". $DB);
  30. }
  31.  
  32.  
  33. ?>
 
Join Date: Feb 2010
Posts: 12
#7: Feb 10 '10

re: PHP login script displays blank


the problem I am seeing is that it never gets there. . . . I never see connect.php in the address bar of the browser, or will I?
 
Join Date: Feb 2010
Posts: 2
#8: Feb 10 '10

re: PHP login script displays blank


I think your problem is your connection file. Try requiring it rather than including it. Also, make sure the details are correct. Tested it and it works fine on my server.
 
Join Date: Feb 2010
Posts: 2
#9: Feb 10 '10

re: PHP login script displays blank


Expand|Select|Wrap|Line Numbers
  1.  $open_data = connect_dbase("login");
  2.  
Don't understand why you have this. Wouldn't it just be:

Expand|Select|Wrap|Line Numbers
  1. connect_dbase("login");
  2.  
OR put your sql as:

Expand|Select|Wrap|Line Numbers
  1. $query = mysql_query("SELECT * FROM users WHERE userid = '$username'", $open_data);        
  2.             $rows = mysql_numrows($query);
  3.  
mmm
 
Join Date: Feb 2010
Posts: 12
#10: Feb 10 '10

re: PHP login script displays blank


lol. I was just coming on to let you know that I fixed it, and it works. . . . I rewrote the section where it checks the database for the username and password so that it reflects the more secure mysql_real_escape_string and that part is working great as well.

that part is working great. . . . .but I have a LOOOOOONNNNNNNNGGGGGG way togo on this project. .. lol
 
Join Date: Feb 2010
Posts: 12
#11: Feb 10 '10

re: PHP login script displays blank


thank you so much for your help. . . .
 
Join Date: Feb 2010
Posts: 12
#12: Feb 10 '10

re: PHP login script displays blank


took out that erroneous variable. . . . .leftovers from a bad idea.
Reply

Tags
calling php files, directory structure, login