Updating database depending on form results

I’ve got a huge form that it used for keep track of stock. The problem is that I’ve added a field for stock for the shop and want to update the online stock depending on which product was changed. The problem is that people won’t be changing one product at a time but could be change 10, 20, 100 or whatever so I ned to make sure that the right product is updated. Also the number could go up as well as down and should also adjust the online stock depending on what entered in the shop field for that product. So far it works if one product has it’s shop stock increased. It doesn’t work if it decreases or if multiple products are changed.

This is what I’ve got at the moment:

    if( isset( $_POST['shop-1-'.$row['id']] ) && ctype_digit( $_POST['shop-1-'.$row['id']] ) ) {
		if ( $row['shop'] > $_POST['shop-1-'.$row['id']] ) { // checks if the shop stock is higher
      $query="update stock set online=online+".$_POST['shop-1-'.$row['id']].",shop=".$_POST['shop-1-'.$row['id']].",shop_date=".time()." where id=".$row['id'];
      dbUpdate( $query,"dbLinkInt" );
		} elseif ( $row['shop'] < $_POST['shop-1-'.$row['id']] ) { // checks if the shop stock is lower
      $query="update stock set online=online-".$_POST['shop-1-'.$row['id']].",shop=".$_POST['shop-1-'.$row['id']].",shop_date=".time()." where id=".$row['id'];
      dbUpdate( $query,"dbLinkInt" );
		} elseif ( $row['shop'] == $_POST['shop-1-'.$row['id']] ) { // checks if the shop stock doesn't change
      }
		}

Thanks in advanced for any help with this.

Why is it important if your stock goes up or down? If there is a new value just update the db. I presume your form prepopulates the form so just put all those values in to the db regardless of whether they are new or not.
I am new to this myself so probably shouldn’t be posting.

Thanks ofeyofey I understand what you’re saying but what I need to do is have the online stock change with the results of the shop stock because everything that is in the shop is taken from the online stock if that makes sense. That way people have a record of what is taken (or put back) and well as can see straightaway how stock there is in total.

You’re right though the fields are pre-populated

Ok I understand you.So you want to record the change in stock as well as the current value.

Yep thats the one :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.