Login System Fail [on hold]

I am trying to login to my website with the information that i put in the database but when i click login it keeps taking me back to the home screen .
I want it to go into the home.php file , but it goes right in and comes right back out .

signin.php:

<?php
include("db.php");

session_start();

if(isset($_POST['login'])){
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);

$sql = "SELECT id, username, password FROM users WHERE username =   '$username' AND activated = '1' LIMIT 1";
mysqli_query($conn, $sql);

if($query){
    $row = mysqli_fetch_row($query);
    $userid = $row[0];
    $dbusername = $row[1];
    $dbpassword = $row[2];
}

if($username == $dbusername && $password == $dbpassword){
$_SESSION['username'] = $username;
$_SESSION['id'] = $userid;
header('Location: home.php');
} else {
echo"Incorrect username or password. Please try again.";
} 
}
?>

<html>

<body bgcolor="#E6E6FA">

<h1><center>Login</center></h1>

<form action="home.php" method="post">
   <p align="center"><input type="text" name="username" size="35" id="Username" placeholder="Username" /></p>
    <br></br>
   <p align="center"><input type="password" name="password" size="35"  id="Password" placeholder="Password" /></p>
    <center><input type="submit" name="login" value="Login"/></center>
    <input type="hidden" name="login" value="blah"/>

   <h3 style="font-size: 20px"><a href="register.php">Go Back To Home Screen</a></h3>  
</form> 

 </body>
</html>

home.php:

<?php

session_start();

if(!isset($_SESSION['id'])){
header("Location: register.php");
} 

?>

<html>
<head>
<title>Interface</title>
</head>
<body>
<h1>Welcome back </h1>
</body>
</html>


Source: wampserver

Leave a Reply