Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

blank screen after php auth script

Posted on 2012-03-26
12
Medium Priority
?
271 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
10 Comments
 
LVL 111

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 111

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
Independent Software Vendors: 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 111

Accepted Solution

by:
Ray Paseur earned 600 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 111

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

876 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