How to Check Conditions with Mysql
<p>I am updating this question to better clarify what am looking for...so I am passing an array to a function which is supposed to update a cart...I have two variables, $isbn and $formatQuantiy...
Here is my problem before updating the database I need to check a few condition
1. check if isbn exists, if it does just update $formatQuantiy, if it does not create a column with isbn as primary key
2. $formatQuantity could be softcover,hardcover, or ebook...I need to update the quantity of the right column so if format is softcover I need to add 1 to the current value of column softcover purchase..
Here is my code...
P.s I know how to do everything else but I don't know how to check the condition with MySQL</p>

<pre><code>&lt;?php
  function insertBook($db,$selection){
    $isbn;
    $format;


   foreach ($selection as $key =&gt; $value) {
       $isbn=$key;
       $format=$value;
       $change= explode(":", $format) ;
       $format=$change['0'];


   }


$query = "INSERT INTO cart (isbn, hardcover_purchased, softcover_purchased, ebook_purchased)
          VALUES (':isbn', ':format', 0, 0)";

$statement = $db-&gt;prepare($query);
$success = $statement-&gt;execute();
$statement-&gt;bindValue(':isbn', $isbn);
$statement-&gt;bindValue(':format', $format);
$statement-&gt;closeCursor();
if ($success) {
  echo "section inserted using query insertNewSection_checkSuccess";
}
else{
  echo "Unable to insert new section using query insertNewSection_checkSuccess";
}
}

 ?&gt;
</code></pre>