I’m back with another absolute beginner question, I have values stored in a database, my goal is to allow users to either subtract or add to a specific database value (quantity) using a drop down menu with values from ranging from 1 – 10. I’m keeping it simple for now.
mysql_select_db("toner", $con);
$sql=INSERT INTO inventory (partnumber, quantity)
VALUES
('$_POST[partnumber]','$_POST[quantity]');
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
I can find plenty of examples just adding or deleting a static value however that’s not what I need. I’ve searched around and few examples resembling what I’m looking for 1 & 2 It seems as though UPDATE would be the best solution however I’m not sure exactly how it should be implemented, I’ve also looking into concatenation but I’m not sure it can accomplish what I need, any assistance you can offer this novice is appreciated. Thanks
To get the following solution to work you will need to insert a value into the database for instance partnumber = 1 and qantity = 0. You will definatly need to modify this to work with your mysql connection string and will need to look in the database after to check that it has worked or add a select query. However this will update the inventory item 1’s quantity with that selected in the dropdown…
file.php
Note: This can easily be extended to specify which partnumber you want to UPDATE in the database by adding say another dropdown or inputbox, catching the value posted and passing it through the where part of the Update query.
THIS HAS NO VALIDATION WHATSO EVER! It is also using depreciated MySQL connection functions, please look up MySQLi and PDO