phpstuck Posted February 6, 2010 Share Posted February 6, 2010 I am building an inventory tracking program. I have configured a barcode scanner to enter info into the inventory data base, this all works great. The problem I am having is trying to update a field in the database named quantity. On the form for scanning there are two fields... First is quantity, second is UPC... We manually enter 10 for the 10 new cans of corn we are adding with the same UPC number.... I need the database to find the current number in the database and then add the 10 I just scanned. I'm not able to find much on this I have googled and come up with nothing. <?PHP include_once 'test.html'; include_once 'db.php'; $quan = $_POST['quan']; $upc = $_POST["upc"]; echo $upc; echo "<BR>"; $contlist=mysql_query( "SELECT * FROM inven WHERE upc='$_POST[upc]'"); while ($all = mysql_fetch_array($contlist)) { $quan1 = $all['quant']; $upc1 = $all['upc']; $brand = $_SESSION['brand']; $descrip = $all['descrip']; $size = $all['size']; $flavor = $all['flavor']; $cat = $all['cat']; } //check that upc does not already exist $sql_user_check = mysql_query("SELECT upc FROM inven WHERE upc='$_POST[upc]'"); $user_check = mysql_num_rows($sql_user_check); if(($user_check > 0)){ echo "<center><b><font face='tahoma' color='black'>Updated ".$descrip." </b><br />"; //RIGHT HERE IS WHERE I AM STRUGGLING $sql = mysql_query("UPDATE inven SET quant='(quant)+($_POST[quan]') WHERE upc='$_POST[upc]'"); if(!$sql){ echo 'A database error occurred while creating your account.'; } }else{ Quote Link to comment Share on other sites More sharing options...
alexjb Posted February 8, 2010 Share Posted February 8, 2010 Maybe you can clarify some things for me. Does this query only return one row? $contlist=mysql_query( "SELECT * FROM inven WHERE upc='$_POST[upc]'"); If so, then the $quan1 variable contains the current quantity, and you just want to increase this by 10, right? In which case, your update query would simply be: $sql = mysql_query("UPDATE inven SET quant='" . ($quan1 + intval($_POST[quan])) . "') Something along those lines. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.