0

I am trying to login in a user and then redirect them, the login is passing as im getting a 1 back however its not redirecting using the header function

php code bellow

<?php
session_start();
$conn = new PDO('mysql:host=localhost;dbname=root', 'root', 'root');
if(isset($_POST['username'],$_POST['password']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$stmt = $conn->prepare("SELECT * FROM User WHERE Username = ? AND Password = ?"); // SQL Statement that selects all the Users credentials.
$stmt->bindParam(1, $username, PDO::PARAM_STR,45); // the bind parameter will insert the username variable into the SQL Statement.
$stmt->bindParam(2, $password, PDO::PARAM_STR,45); // the bind parameter will insert the password variable into the SQL Statement.
$stmt->execute(); // This executes the sql statements above.
$count = $stmt->rowCount(); // This produces a row count to see if the credentials used are in the database.
echo $count;
if($count == 1) { // this if statement will check the users credentials found in the Database.
  $_SESSION['loggedin'] = "1";
  header("location: Homepage.php",  true,  301 ); // if successfull the user shall be directed to the homepage of RealReels
 }
 else { //  the else statement is the outcome if the users credentials not found in the Database.
   $_SESSION['loggedin'] = "0";
   header ("Location: login.php"); // if not succcessful the user is linked to the Log_in.php error page.
 }
}
?>

html form

<form name="input" action="Log_in_validation.php" method="POST">

<label for="User_name" >Username:</label>
<input type="text" name="username">

  <label for="Password" >Password: </label>
<input type="password" name="password">

<input type="submit" value="Log In"/>
</form>
gurps
  • 121
  • 1
  • 4
  • 10

0 Answers0