i have not been able to get this, i have been on this for days ,i dont know if its from the login page or the dashboard , but my login script doesnt redirect to the dashboard
i have tried alot of things and even added an echo at every line of code , it shows that , the scripts get to the redirect and actually redirects but still comes back to the login page
<?php require 'sqlconnect.php' ?>
<?php
session_start();
?>
<?php
$email= '';
$password = '';
$errors = '';
$success = '';
if(isset($_REQUEST['login'])){
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
if(empty($email)){
$errors .= '<div class="alert alert-danger" role="alert">
Email field is empty.
</div>';
}
if(empty($password)){
$errors .= '<div class="alert alert-danger" role="alert">
Password field is empty.
</div>';
}
if(!empty($email) and !empty($password)){
$confirm_info = mysqli_query($connection, "SELECT * FROM users WHERE email = '$email' AND password = '$password'");
if(mysqli_num_rows($confirm_info) >= 1){
echo "if statement";
while($results = mysqli_fetch_assoc($confirm_info)) {
$token = $results['token'];
$token = $_SESSION['token'];
header("Location: dashboard/profile.php");
}
}else{
$errors .= '<div class="alert alert-danger" role="alert">
Login credentials doesn\'nt exist is our database.
</div>';
}
}
}
?>
</head>
<body>
<form class="login100-form validate-form" method="POST" action="login.php">
<span class="login100-form-title p-b-37">
Sign In
<!-- <i class="fa fa-home uk-align-center uk-text-center"></i> -->
</span>
<?php
echo $errors;
//echo $success;
?>
<br>
<div class="wrap-input100 validate-input m-b-20" data-validate="Enter username or email">
<input class="input100" type="email" name="email" placeholder="email" value="<?php echo $email ?>">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input m-b-25" data-validate = "Enter password">
<input class="input100" type="password" name="password" placeholder="password">
<span class="focus-input100"></span>
</div>
<div class="container-login100-form-btn">
<button class="login100-form-btn" id="login" name="login">
Sign In
<i class="fa fa-spinner fa-spin" id="spinner" style="display: none"></i>
</button>
</div>
<div class="text-center p-t-57 p-b-20">
<span class="txt1">
<a href="forgetpassword.php" class="txt2 hov1">
forget password
<i class="fa fa-long-arrow-right m-l-5"></i>
</a>
</span>
</div>
<div class="text-center p-t-57 p-b-20">
<span class="txt1">
Or Create an account
</span>
</div>
<!-- <div class="flex-c p-b-112">
<a href="#" class="login100-social-item">
<i class="fa fa-facebook-f"></i>
</a>
<a href="#" class="login100-social-item">
<img src="login/images/icons/icon-google.png" alt="GOOGLE">
</a>
</div> -->
<!--
<div class="text-center">
<a href="#" class="txt2 hov1">
Sign Up
</a>
</div> -->
</form>
<div class="container-login100-form-btn">
<a href="signup.php" class="txt2 hov1 text-light">
<button class="signin100-form-btn">
Sign Up
</button>
</a>
</div>
</div>
</div>
</body>
</html>
And this is the dashboard profile page code
<?php require '../sqlconnect.php' ?>
<?php
session_start();
$token = $_SESSION['token'];
if(!isset($_SESSION['token'])){
header("Location: ../login.php");
exit();
}else{
$all_details = mysqli_query($connection, "SELECT * FROM users WHERE token = '$token'");
if(mysqli_num_rows($all_details)){
$results = mysqli_fetch_assoc($all_details);
$id = $results['id'];
$token = $results['token'];
$email = $results['email'];
$first_name = $results['first_name'];
$is_admin = $results['is_admin'];
$last_name = $results['last_name'];
$usernam = $results['username'];
$image_name = $results['image_name'];
$image_dir = $results['image_dir'];
// echo $username;
}
}
?>