Jump to content

Positioning Input Field Of Login.php


Guest Postmanpat
 Share

Recommended Posts

Guest Postmanpat

Hello,I need some help, please!Until now I had a very goog working login.php script. But now I want to position it with 'div' and 'table' and it stops working (white page after login).Do I have to redirect the header? If so, how? Or what's the reason?Thank you.

 <?php session_start(); // Starts the session. ?> <html><head></head><body><div id="layer1" style="position: relative; width: 200px; height: 400px; z-index: 1">	<table style="width: 100%; margin-top: 150px; height: 100px"><tr><td>  <?php include("conf.inc.php"); // Includes the db and form info. session_start(); // Starts the session. if ($_SESSION['name'] == '$name') { // User is already logged in.     header("Location: homepage.php"); // Goes to main page.     exit(); // Stops the rest of the script. } else {     if (!isset($_POST['submit'])) { // The form has not been submitted.         echo "<form action=\"login.php\" method=\"POST\">";         echo "<table>";         echo "<tr>";         echo "<td colspan=\"2\">Login:</td>";         echo "</tr>";         echo "<tr>";         echo "<td width=\"50%\">Lastname:</td><td width=\"50%\"><input name=\"name\" size=\"18\" type=\"text\" />";         echo "</tr>";         echo "<tr>";         echo "<td width=\"50%\">Password:</td><td width=\"50%\"><input name=\"password\" size=\"18\" type=\"text\" />";         echo "</tr>";         echo "<tr>";         echo "<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"submit\"</td>";         echo "</tr>";         echo "</table>";         echo "</form>";     } else {         $name = form($_POST['name']);         $password = md5($_POST['password']); // Encrypts the password.         $q = mysql_query("SELECT * FROM `users` WHERE name = '$name' AND password = '$password'") or die (mysql_error()); // mySQL query         $r = mysql_num_rows($q); // Checks to see if anything is in the db.         if ($r == 1) { // There is something in the db. The name/password match up.             $_SESSION['name'] = $name; // Sets the session.                         header("Location: homepage.php"); // Goes to main page.             exit(); // Stops the rest of the script.         } else { // Invalid name/password.             exit("Incorrect name/password!<br /><a href=\"login.php\">Back to Login</a>"); // Stops the script with an error message.         }                 } } mysql_close($db_connect); // Closes the connection. ?>  </td></tr></table></div></body></html>

Link to comment
Share on other sites

You can't send headers after you send HTML code. The PHP code needs to go before the HTML code. Use variables in PHP to hold whatever information you want to add to the HTML, but the PHP code needs to go before the HTML if you're going to use headers (including session_start).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...