title: I want in this code please to increase the quantity of same item when insert without add new record to the table
body: <p>I want in this code please to increase the quantity of the same item when inserting<br>
     without adding a new record to the table. 
     the insert working is done, but please I need when inserting to the table that 
    contains a unique number of the invoice to increase the number of items without 
    duplicate records.</p>
  
  <pre><code>   &lt;?php
      session_start();
      include('../connect.php');
      $a = $_POST['invoice'];
      $b = $_POST['product_id'];
      $c = $_POST['qty'];
      $saleproduct = $_POST['saleproduct'];
      $w = $_POST['pt'];
      $amount = $_POST['amount'];
      $dateok = $_POST['dateok'];
      $result = $db-&gt;prepare("SELECT * FROM products WHERE product_id= :userid");
      $result-&gt;bindParam(':userid', $b);
      $result-&gt;execute();
      for($i=0; $row = $result-&gt;fetch(); $i++){
      $sellprice=$row['price'];
      $prodcode=$row['prod_code'];
      $code=$row['product_code'];
      $color=$row['color_name'];
      $size=$row['size_name'];
          $sizenum=$row['note'];
      $name=$row['product_name'];
      }
  
      $sql = "UPDATE products 
              SET qty=qty-?
              WHERE product_id=?";
      $q = $db-&gt;prepare($sql);
      $q-&gt;execute(array($c,$b));
      $grandtotal = $sellprice- $saleproduct ;
      $d=$grandtotal*$c;
      $sql = "INSERT INTO sales_order 
  
  
  (invoice_number,prod_code,product_id,qty,amount,saleproduct,name,color_name,size_name,note,price,product_code,date,dateok) VALUES 
      (:a,:prodcode,:b,:c,:d,:saleproduct,:e,:ee,:eee,:sizenum,:sellp,:i,:k,:kok)";
      $q = $db-&gt;prepare($sql);
      $q-&gt;execute(array(':a'=&gt;$a,':prodcode'=&gt;$prodcode,':b'=&gt;$b,':c'=&gt;$c,':d'=&gt;$d,':saleproduct'=&gt;$saleproduct,':e'=&gt;$name,':ee'=&gt;$color,':eee'=&gt;$size,':sizenum'=&gt;$sizenum,':sellp'=&gt;$sellprice,':i'=&gt;$code,':k'=&gt;$date,':kok'=&gt;$dateok));
      ?&gt;
  </code></pre>