Changed my code to the following thanks to the tips. But I'm still not redirected to the user.php. Added the variable $rowcount and give it a value. If the query has a value of a user it have to be redirected to the user.php page.
<?php
include("inc/header.php");
?>
<?php
if(isset($_POST["submit"])) {
$username = trim($_POST["username"]);
$password = trim($_POST["password"]);
if($username == "" && $password == "") {
echo "Please fill in all the details";
exit;
}
if($username == "admin" &$password == "test") {
$_SESSION["admin"] = true;
header("location: admin-panel.php");
}
$rowcount = 0;
$password_secure = md5($password);
if($username != "" && $password != "") {
$sql = "SELECT * FROM user WHERE username = '".mysqli_escape_string($connection, $username)."'
AND password = '".mysqli_escape_string($connection, $password_secure)."'";
$query = mysqli_query($connection, $sql);
$rowcount = mysqli_num_rows($query);
} else {
echo "Username of password was not right, please try again.";
}
if($rowcount != 0) {
$row = mysql_fetch_array($connection, $query);
$_SESSION["username"] = $row["username"];
$_SESSION["login"] = true;
header("location: user.php");
exit;
}
}
?>
<?php
include("inc/footer.php");
?>