php - Only change the quantity when product already exists in database -


i have problem kind of 'webshop' i'm building add products in database want change quantity when product exists.

i don't know how achieve this. can maybe me function check if product exists can add +1 ['aantal'] everytime add product exists?

the post is:

if(isset($_post['submit-bonbon'])){     $postgewicht = $_post['gewicht'];      $bonbonname = $_post['product'];     $image = $_post['afbeelding'];     $quantity = $_post['aantal'];      $jsondata = unserialize($_session['json_data']);       if(count($jsondata,1) >= 1){         $jsondata['bonbons'][] = array('gewicht' => $postgewicht,'name' => $bonbonname,'afbeelding' => $image, 'aantal' => $quantity);     } else {          $bonbonsarray[] = array('gewicht' => $postgewicht,'name' => $bonbonname,'afbeelding' => $image, 'aantal' => $quantity);          $order = array('userid' => $bonbonuser, 'bonbons' => $bonbonsarray);         $jsondata = $order;     }      $_session['json_data'] = serialize($jsondata);     $orderdata = $_session['json_data'];      $query = mysql_query("select * cms_bonbonorder userid='$bonbonuser'");     mysql_query("update cms_bonbonorder set jsondata='$orderdata' userid='$bonbonuser';"); } 

so put json string in database looks example:

array (     [bonbons] => array         (             [0] => array                 (                     [gewicht] => 16                     [name] => test                     [afbeelding] => amarena%2020g1.jpg                     [aantal] => 1                 )              [1] => array                 (                     [gewicht] => 16                     [name] => test                     [afbeelding] => amarena%2020g1.jpg                     [aantal] => 1                 )              [2] => array                 (                     [gewicht] => 16                     [name] => test                     [afbeelding] => amarena%2020g1.jpg                     [aantal] => 1                 )              [3] => array                 (                     [gewicht] => 18                     [name] => testbonbon 2                     [afbeelding] => bresil%2017g1.jpg                     [aantal] => 1                 )              [4] => array                 (                     [gewicht] => 16                     [name] => test                     [afbeelding] => amarena%2020g1.jpg                     [aantal] => 1                 )          )  ) 

i hope made myself clear enough!

thanks


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -