473,497 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP login script displays blank

12 New Member
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.
Feb 9 '10 #1
11 2508
Atli
5,058 Recognized Expert Expert
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!)
Feb 9 '10 #2
Mathanan
12 New Member
I get a blank screen with the browser pointing at the login.php file
Feb 9 '10 #3
Mathanan
12 New Member
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. . . .
Feb 9 '10 #4
Atli
5,058 Recognized Expert Expert
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.
Feb 9 '10 #5
Mathanan
12 New Member
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. ?>
Feb 10 '10 #6
Mathanan
12 New Member
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?
Feb 10 '10 #7
Phill
4 New Member
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.
Feb 10 '10 #8
Phill
4 New Member
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
Feb 10 '10 #9
Mathanan
12 New Member
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
Feb 10 '10 #10
Mathanan
12 New Member
thank you so much for your help. . . .
Feb 10 '10 #11
Mathanan
12 New Member
took out that erroneous variable. . . . .leftovers from a bad idea.
Feb 10 '10 #12

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

Similar topics

7
1530
by: Cemal Karademir | last post by:
Hi, I'm workin on a small Login page/program with asp.net. It uses an MS-Access database that looks like this: USERID | NAME | PASSWORD _________________________________ 1 ...
15
2263
by: carr4895 | last post by:
Hello. I was wondering if someone could help me too with a login form. Upon startup, I have to display a password screen and it should accept a user name and password. User name can be anything...
12
13971
by: Murali via DotNetMonster.com | last post by:
Hi All I am new to .net, as i worked majorily on VB6.0 & Crystal reports, I have developed an Window application in VB.net/SQL Server2000 and using Crystal reports8.5, I have used the CRViewer in...
3
5764
by: ilockett | last post by:
The background: I have a web app with a simple master page that contains just one content placeholder. I have created a web form that then uses this master page. Within the content...
2
2022
by: Tom | last post by:
I hope someone can help me figure out what's going on here. I've re-read the section on sessions at php.net and Googled this high and low but I haven't found anything that quite explains my...
3
5371
by: focussys | last post by:
hi i am a student and am doing this for one of my assignments i am trying to create a login using perl and mysql database.i was succesful in doing that now i want to use cookies for...
0
5239
by: muder | last post by:
I have a standard Login ASP.NET 2.0 control on a login Page, a LoginName and LoginStatus controls on the member's page. once the user login successfully I am redirecting the user to Member.aspx...
8
2091
tolkienarda
by: tolkienarda | last post by:
hi all i have a login script that is simplified with out any extra stuff. and it doesn't seem to work. i think the problem is something to do with session variables. but i am not sure what it is....
3
6207
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
9
7501
by: adweaver | last post by:
Hello All, I'm new to the world of php. I've just had a site designed for me by a company, and I'm now trying to manage and grow it, so it will suit my needs. The site was built in a folder...
0
6991
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
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6878
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...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.