<?php
session_start();
include("db.php");
if($_SERVER['REQUEST_METHOD'] !== 'POST'){
    header("Location: index.php");
    exit;
}

if(empty($_POST['username']) || empty($_POST['password'])){
    header("Location: index.php?Empty=Empty username or password");
    exit;
}

$username = $_POST['username'];
$password = $_POST['password'];

$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysqli_query($conn, $query);
if($result && mysqli_num_rows($result) == 1){
    $_SESSION['User'] = $_POST['username'];
    header("Location: welcome.php");
    exit;
}else{
    header("Location: index.php?Invalid=Wrong username or password");
    exit;
}
?>
