<?php
include "stuff.php";
$con = mysqli_connect($server,$user,$password,$db);
$username = $_POST['username'];
$password = $_POST['password'];

if(is_string($username) && $username != "")$username=trim($username);

$res = mysqli_query($con,"SELECT id FROM users WHERE email = '{$username}' AND password = '{$password}'");
$row = mysqli_fetch_array($res);
$user_id = (int)$row['id'];

if($user_id > 0){
    $logged_in_elsewhere = log_user_in($user_id,$con);
    header("location: ../index.php?LGE={$logged_in_elsewhere}");
}else{
  echo ("<script>alert('password or user name not recognised use back browser button to start over')</script>");
  exit;
}
?>
