Solved

blank screen after php auth script

Posted on 2012-03-26
12
264 Views
Last Modified: 2012-06-20
Guys,

For some reason I cant see the issue here, can anyone see with a fresh pair of eyes why i am getting a blank load screen.

<?php
include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
  $email=$_POST['email'];
  $password=$_POST['password'];
  $email=strip_tags($email);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "SELECT * from users where email='$email' and password='$password'";
  $result = mysql_query($query) or die ("could not access users database");
  $result2 = mysql_fetch_array($result);
  if ($result2)
   {
     $_SESSION['id']=$id;

     echo "Logged In <br>";
     echo "<a href='members.php'>Continue</a>";
     exit;
  }
  else
  {
  echo "Wrong Email or Password. <a = href='login.php'>Try Again</a>";
  }
}
?>
0
Comment
Question by:nullag
  • 4
  • 4
  • 2
12 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37769120
Here is an article that addresses PHP client authentication.  It's a good place to start.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391.html

 Your script may contain a parse error.  Add these two instructions as the first two after <?php and run it again.
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

Open in new window

0
 

Author Comment

by:nullag
ID: 37769138
I added both lines of code, it still loads black

I will have a look at the link as well.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37769203
I ran the script standalone and got some messages.  Of course it could not do anything because I do not have your data base, and I did not post any data to the script.  But at least we ruled out PHP parse errors. Try it on my server here.
http://www.laprbass.com/RAY_temp_nullag.php

Maybe if you can post the <form> script that sends its POST data to this script we can find a problem.  Just a thought, ~Ray
<?php // RAY_temp_nullag.php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
  $email=$_POST['email'];
  $password=$_POST['password'];
  $email=strip_tags($email);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "SELECT * from users where email='$email' and password='$password'";
  $result = mysql_query($query) or die ("could not access users database");
  $result2 = mysql_fetch_array($result);
  if ($result2)
   {
     $_SESSION['id']=$id;

     echo "Logged In <br>";
     echo "<a href='members.php'>Continue</a>";
     exit;
  }
  else
  {
  echo "Wrong Email or Password. <a = href='login.php'>Try Again</a>";
  }
}

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:nullag
ID: 37769216
This is the POST (Login) page

<form method="POST" action="auth.php">
Email: <input type="text" name="email" size="55">
Password: <input type="password" name="password" size="32" mask="x">
<br>
<input type="submit" value="login" name"submit">

Open in new window

0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37789852
It's very simple
Change line 8 to:

if (isset($_POST['password']))

Open in new window


The reason? Input type=submit is not a field and thus it doesn't get sent in the POST request...
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 150 total points
ID: 37790798
Here is line 5 of the HTML form script
<input type="submit" value="login" name"submit">

Open in new window

and here is what you probably wanted to have instead.  Note the addition of the equal sign on the name attribute
<input type="submit" value="login" name="submit" />

Open in new window

Once you make that change, please try it again and post back if you still have any troubles.  These things are hard to catch because the browsers will try to render something even if you have given them invalid HTML.  But you can always feed your script to the W3 validator and it will often catch these kinds of errors and tell you about them.
http://validator.w3.org/

Best regards, ~Ray
0
 

Author Comment

by:nullag
ID: 38086067
Thanks that worked.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38086112
You're kidding, right?  Can you please post a demonstration of how this solved the problem?

Thanks, ~Ray
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 38087172
Haha!
I was utterly wrong in the reasoning after the fact: my recipe works because it relies on the other input field.

Ray nailed it though, because he found your typo.
Please review this and award him the points.
0
 

Author Closing Comment

by:nullag
ID: 38106178
My typo
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
issue with DB import 1 36
JQuery Search Filter 2 68
Using Modal's in to Retrieve Data from MySql and Populate Forms 13 77
php subtract from date 2 27
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question