<?php ob_start(); ?>
<?php
 include('../config/constants.php');
?>



<?php




if (isset($_POST['add-cart1'])) {
    $prodid = $_POST['id'];
    $userid = $_SESSION['userid'];
    $qty = $_POST['qty'];
    $size = $_POST['size'];
          //redirect
          //header('location:'.SITEURL.'shopping/login.php');
          //echo $_SESSION('userid');
        if (isset($_SESSION['userid'])) {
          // code...
           //$userid = $_SESSION['userid'];
           //1.GET THE DATA FRO FORM
           // $userid =mysqli_real_escape_string($conn, $_POST['userid']);
           // $size =mysqli_real_escape_string($conn, $_POST['size']);
           // $qty =mysqli_real_escape_string($conn, $_POST['qty']);
           // $prodid =mysqli_real_escape_string($conn, $_POST['id']);
            

            // Check if product is already in the cart
          $result1 = mysqli_query($conn, "SELECT * FROM cart WHERE prod_id = $prodid AND user_id = $userid");

        // If product is already in the cart, increment its quantity
          if (mysqli_num_rows($result1) > 0) {
           mysqli_query($conn, "UPDATE cart SET qty = qty + 1 WHERE prod_id = $prodid AND user_id = $userid");
           header('location:'.SITEURL.'shopping/viewcart.php');
          } else {
          // If product is not in the cart, add it
          mysqli_query($conn, "INSERT INTO cart (prod_id, user_id, qty, size) VALUES ($prodid, $userid, $qty, $size)");
          header('location:'.SITEURL.'shopping/viewcart.php');
        }
            //$price = mysqli_real_escape_string($conn, $_POST['price']);
           
            //$size = mysqli_real_escape_string($conn,$_POST['size']);
            //CHECK if featured and active are checked or not
           
           //2UPLOAD IMG IF SELECTED
           //check if the select img is clicked or not and upload the img only if the img selected
          
                
           //3. INSERT data TO DB
           //create sqlto save data in the db
          
           //execute the querry
          /// $res2 = mysqli_query($conn, $sql2);
           //check whether the data is inserted or not
           //4.REDIRECT WITH MSG TO MANAGE FOOD PAGE
           
      
         }
         else{
           $_SESSION['verify'] = "<div class='success'>Login first to add things to cart.</div>";
             header('location:'.SITEURL.'shopping/login.php');
         }
}
     
        
    












 ?>
