<?php session_start();
include("includes/db_config.php");
if(isset($_POST["login"])) 
{   extract($_POST);  
      //var_dump($_POST);exit();
$email = $_POST["email"]; 
$password = $_POST["password"]; 
$email = stripslashes($email);
$password = stripslashes($password);
$sql ="SELECT count(*) as num FROM user_profile WHERE email = '".$email."' AND  password = '".$password."'";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$res= mysqli_fetch_array($result);
$count=$res['num']; 
if($count > 0 )
{ 
$_SESSION['loggedin'] = true;
$_SESSION['email'] = $email;
$email_id=$_SESSION['email'];
$sql1="select id,email from user_profile where email='".$email_id."'";
$result1 = mysqli_query($conn, $sql1);
$res1= mysqli_fetch_array($result1);
$_SESSION['id']=$res1['id'];
echo $user_id=$_SESSION['id'];
$session_id =$_SESSION['prd_session_id'];
$sql_upd ="UPDATE  addto_cart  SET user_id='$user_id'  WHERE session_id='$session_id' and invoice_id='1'"; 
$res_upd=mysqli_query($conn,$sql_upd) or die(mysqli_error());

echo '<script>alert("Login successfully")</script>'; 
echo "<script>window.location.href='index.php'</script>";
}
else
{  echo '<script>alert("The username or password are incorrect!")</script>'; 
}
} ?>
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content=" ">
    <meta name="author" content="">
    <title>Orange Groceries</title>
    <?php include("includes/css.php");?>
</head>

<body style="background-color:#f9f9f9;">
    <?php include("includes/header.php");?>
    <section class="shop-list section-padding">
        <div class="container">
            <div class="row">
                <div class="col-md-2 hidden-xs"></div>
                <div class="col-md-8 col-sm-8 col-xs-12">
                     <div class="row loginsignbox">
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <div class="mb-0">
                                <div class="row">
                                    <div class="col-md-12">
                                        <h2 class="text-center text-uppercase pt-20">Login Form</h2>
                                    </div>
                                    <div class="signupbox-form form-logins" style="width:100%;">
                                        <form class="login-form" method="POST" action="">
                                            <div class="form-group">
                                                <div class="col-md-12 col-xs-12 mb-15">
                                                    <label style="font-size:15px;color:#000;">Email-Id</label>
                                                    <input type="email" name="email" class="form-control email-login" placeholder="Enter Email-Id" required="">
                                                    <div class="alert alert-warning" id="result" style="display: none;"> </div>
                                                </div>
                                                <div class="col-md-12 col-xs-12 mb-15">
                                                    <label style="font-size:15px;margin-top:10px;color:#000;">Password</label>
                                                    <input type="password" id="chpassword" name="password" placeholder="Enter Password" class="form-control" required="">
                                                </div>
                                            </div>

                                            <div class="clearfix"></div>
                                            <div class="col-md-12 col-xs-12 mb-15">
                                                <div class="dloginhide hidden">
                                                    <div class="clearfix"></div>
                                                    <div class="product_details_box product-add-to-cart-btn" style="margin-top:25px;">
                                                        <a style="width:100%; text-align:center; font-size:16px;padding:0px;">
                                                            <input type="submit" name="login" value="Login Here" class="btn btn-lg btn-block inpt-control" style="background-color:#ed1d24;color:#fff;font-weight:600;"> <i class="mdi mdi-user" aria-hidden="true"></i>
                                                        </a>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                        <div class="col-md-12">
                                            <h6 class="text-center pt-5 text-black" style="margin-top:20px;">Don't have an account? <a href="https://orangegroceries.com/signup.php" style="color:#000;"> <strong>Please Sign Up</strong></a></h6>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <div class="loginbody_right">
                                <div class="text-center mb-20 mt-20">
                                    <img src="https://orangegroceries.com/img/logo.png" width="200px;" alt="">
                                </div>
                                <div class="lgoinleft_des mt-20">
                                    <div class="left_desimg"><img src="https://orangegroceries.com/img/login_watch.png" alt=""></div>
                                    <div class="left_descont">Manage your Order Easily Track Order, Hassle Free Return.</div>
                                </div>
                                <div class="lgoinleft_des" style="margin-top:30px">
                                    <div class="left_desimg"><img src="https://orangegroceries.com/img/track_icon.png" alt=""></div>
                                    <div class="left_descont">OG Express Delivery for Daily Needs Products.</div>
                                </div>
                                <div class="lgoinleft_des">
                                    <div class="left_desimg"><img style="height: 24px;width: 23px;" src="https://orangegroceries.com/img/my_wallet_logo.png" alt=""></div>
                                    <div class="left_descont">OG Wallet for making Payments and getting Cash Back.</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <?php include("includes/footer.php");?>
    <?php include("includes/js.php");?>

    <!--  <script>
        jQuery(function() {
            jQuery('#in1').fastLiveFilter('#f1');
        });

    </script> -->
    <script type="text/javascript">
        $(document).ready(function() {
            $(".email-login").keyup(function() {
                searchid = $(this).val();
                dataString = 'search=' + searchid;
                if (searchid != '') {
                    $.ajax({
                        type: "POST",
                        url: "reg_validation.php",
                        data: dataString,
                        cache: false,
                        success: function(html) {
                            $("#result").html(html).show();
                        }
                    });
                }
                return false;
            });
        });

    </script>
</body>

</html>
