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

    if (isset($_POST['add-cart1'])) {
        // code...

    echo $prodid = $_POST['prodid'];
    echo $userid = $_SESSION['userid'];
   echo  $qty = $_POST['qty'];
    echo $size = $_POST['size'];
    }
    if(isset($_SESSION['userid'])){
       //echo $userid = $_SESSION['userid'];

        $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 = "INSERT INTO cart SET
            prod_id = '$prodid',
            user_id = '$userid',
            size = '$size',
            qty = '$qty'
            ";
            $msqlres = mysqli_query($conn, $mysqli_query);
          
          header('location:'.SITEURL.'shopping/viewcart.php');
        }
    }else{
        header('location:'.SITEURL.'shopping/login.php');
    }

?>