<?php
require_once './connection.php';
if (!isset($_POST['username']) == "" || !isset($_POST['password'])) {

    $username = $_POST['username'];
    $password = $_POST['password'];
//    $password = md5($password1);
    $query = 'select * from tbl_user where username="' . $username . '" and password="' . $password . '"';
//    echo 'query '.$query;
    try {
        
        $result = mysqli_query($con, $query);
        if ($result) {
            if (mysqli_num_rows($result) > 0) {
                while ($row1 = mysqli_fetch_assoc($result)) {
                    session_start();
                    // $_SESSION['username'] = $username;
                    $_SESSION['username'] = $row1['name'];
                    $_SESSION['user_id'] = $row1['id'];
                    $_SESSION['bg_img_url'] = $row1['bg_img_url'];
                    $_SESSION['User_language'] = 'GUJARATI';
                    echo "Login Success .....";
                    exit();
                }
            } else {
                echo "Username and password not match.";
                exit();
            }
        } else {
            echo "Username and password not match 123.";
            exit();
        }
        
        // $result = mysqli_query($con, $query);
        // if ($result) {
        //     if (mysqli_num_rows($result) > 0) {
        //         session_start();
        //         $_SESSION['username'] = $username;
        //         $_SESSION['loggedin'] = true;
        //         // $_SESSION['User_language'] = 'GUJARATI';
        //         $_SESSION['User_language'] = 'ENGLISH';
        //         echo "Login Success .....";
        //         // print_r($_SESSION);
        //         exit();
        //     } else {
        //         echo "Username and password not match.";
        //         exit();
        //     }
        // } else {
        //     echo "Username and password not match 123.";
        //     exit();
        // }
    } catch (Exception $ex) {
        
    }
}
?>

