I want to add something to the script below that, prior to insert, check to see if the $CigarID already exists for the $UserID. If so, I want it to do an update and increase the $Quantity by whatever the user inputs. If the value doesn't exist, then insert the full statement. What's the best way to handle this in PHP??
<?PHP
session_start();
//Open Database
include 'dbconnection.php';
//Create Post Variables
$CigarID = mysql_real_escape_string($_POST['Cigar']);
$Quantity = mysql_real_escape_string($_POST['Quantity']);
$DatePurchased = mysql_real_escape_string($_POST['DatePurchased']);
$DatePurchasedFormatted = date("m/d/Y", strtotime($DatePurchased));
$PricePaid = mysql_real_escape_string($_POST['PricePaid']);
$UserID = $_SESSION["UserID"];
//Create SQL Statement Variable
$SQL = "INSERT INTO humidor VALUES (NULL,'$UserID','$CigarID', '$DatePurchasedFormatted','$Quantity','$PricePaid',Now())";
//Insert Entry
if (!mysql_query($SQL))
{
die('Error: ' . mysql_error());
}
?>