<?php
require 'connect.inc.php';
require 'core.inc.php';

if (isset($_POST['email']) && isset($_POST['password'])) {
    $email = $_POST['email'];
    $password = $_POST['password'];
    $password_hash = md5($password);

    if (!empty($email) && !empty($password)) {
        $query = "SELECT `id` FROM `globaly_accounts` WHERE `email` ='" . mysqli_real_escape_string($con, $email) .
                 "' AND `password` = '" .mysqli_real_escape_string($con, $password_hash )."'";
        if ($query_run = mysqli_query($con, $query)) {
            $query_num_rows = mysqli_num_rows($query_run);
            if ($query_num_rows == 0) {
                echo 'invalid email/password combination';
            } else if ($query_num_rows == 1) {
                //treba nam $user_id
                $row = mysqli_fetch_assoc($query_run);
                $user_id = $row['id'];

                $_SESSION['user_id'] = $user_id;
                header('Location: ../index.html');
            }
        } else {
        }
    } else {
        echo 'You must suply email or password';
    }
}
?>