Jump to content

Adding a defined quantity


phpstuck

Recommended Posts

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{

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.