Im slowly getting insane. This time i want that it isnt possible to klick the login in button and get ridirected without typed in a username or a password.
I tryed this:
Redirect after login example 1
Until i ended up with my written code:
<?php
session_start();
require('../includes/connect_to_db.php');
if (isset($_POST['username']) and isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM `user` WHERE username='$username' and password='$password'";
$result = mysqli_query($connection, $query) or die(mysqli_error($connection));
$count = mysqli_num_rows($result);
if (empty($_POST['username'])||
empty($_POST['password'])){
$fmsg = "Invalid Login Credentials.";
}
if(mysqli_num_rows($result)>0){
$_SESSION['username'] = $username;
header("Location:Loginpage.php");
}else{
$fmsg = "Invalid Login Credentials.";
}
}
if (isset($_SESSION['username'])){
$username = $_SESSION['username'];
}
?>
When i type anything in the login form its says :"Invalid Login Credentials" but when i let them empty and just klick on "Login" he redirect to the shown page. I lose my mind i cant find the damn mistake i made.