title: how to add product to cart include size and quantity php
body: <p>I wanna add a product to cart with chosen size and quantity. I've written this codes but my questions are:
   first of , does it work safely and correctly?
  and then if user add one specific product(product_id) twice to cart(in two different request) how can I add the quantities of both requests?
  and finally how should I handle different sizes for one product id?</p>
  
  <pre><code>if (isset($_POST['add2cart'])){
      if (is_numeric($_POST['proId']) and is_numeric($_POST['count']) and ($_POST['count'])&gt;0 and strlen($_POST['size'])&lt;5) {
          $proId= $_POST['proId'];
          $proCount = $_POST['count'];
          $proSize = $_POST['size'];
          if (!isset($_SESSION['cart'])) {
              $_SESSION['cart'] = array('id'=&gt;$proId, 'count'=&gt;$proCount, 'size'=&gt;$proSize);
              $_SESSION['cartStatus'] = 'open';
              $successMsg = 'با موفقیت به کارت اضافه شد .';
          } else {
              if (isset($_SESSION['cartStatus']) and $_SESSION['cartStatus'] == 'open') {
                  $_SESSION['cart'][] = ['id'=&gt;$proId, 'count'=&gt;$proCount, 'size'=&gt;$proSize];
  
                  $successMsg = 'با موفقیت به کارت اضافه شد .';
  
              } else {
                  $errorMsg = 'یک عملیات خرید در جریان است . تا پایان این خرید ،سبد قفل است.';
              }
          }
      }else{
          $errorMsg = 'خطایی در اطلاعات ورودی رخ داده است.';
      }
  
  }
  </code></pre>