Solved

blank screen after php auth script

Posted on 2012-03-26
12
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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…

710 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