header location won't work in php

Posted by Jayden Kelly on Stack Overflow See other posts from Stack Overflow or by Jayden Kelly
Published on 2013-10-26T03:37:15Z Indexed on 2013/10/26 3:54 UTC
Read the original article Hit count: 158

Filed under:

I am making a login page for my website but the header location won't work. here is the code of login.php:

<?php
include ( './includes/header.php' );

if (isset($_POST['submit'])) {
  $username = $_POST['username'];
  $password = $_POST['password'];
 $check_username = mysql_query("SELECT username FROM users WHERE username='$username'");
 $numrows = mysql_num_rows($check_username);
 if ($numrows != 1) {
  echo 'That User doesn\'t exist.';
 }
 else
 {
  $check_password = mysql_query("SELECT password FROM users WHERE password='$password' && username='$username'");
  while ($row = mysql_fetch_assoc($check_password)) {
   $password_db = $row['password'];

   if ($password_db == $password) {
     $_SESSION['username'] = $username;
    header("Location: members.php");
   }
  }
 }
}

?>
<h2>Login to Your Account</h2>
<form action='login.php' method='POST'>
<input type='text' name='username' value='Username ...' onclick='value=""'/><p />
<input type='password' name='password' value='Password ...' onclick='value=""'/><p />
<input type='submit' name='submit' value='Login to my Account' />
</form>

I would really appreciate it if someone could help me, thanks.

P.S.

If you need the php part of the header file it is here:

<?php
session_start();
include ( './includes/functions.php' );
include ( './includes/connect_to_mysql.php' );
?>

© Stack Overflow or respective owner

Related posts about php