texmansru47 Posted May 28, 2008 Share Posted May 28, 2008 I'm baffled. I have this code that I trying to complete that is to do three things: 1) Collect data from a form and used POST data to take that entry and subtract it against the total current QTY in my MySQL Database. 2) Update the two tables (SNAInv and SNAInvHist(this table is the transactions of the add/subtracts from each item in the main INV db) 3) tell it completed. The problem is the only thing NOT working is the subtraction... I get a big fat NADA. Here is the form: <html> <head> <title>Inventory</title> </head> <body bgcolor="#C0C0C0"> <b><img border="0" src="logo1.jpg" width="78" height="77"> <font face="Arial" color="#000080">Inventory - Managing Inventory Input</font></b><font face="Arial" color="#000080"> <P> <form method="POST" name="Recv" action="queryme.php"> <table width="550" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="2" bgcolor="#000000"><span class="style1">Managing Inventory Control</span></td> </tr> <tr> <td bgcolor="#FFCC66">Part Number: </td> <td bgcolor="#CCCCCC"><input name="ProdNum" type="text" id="ProdNum"></td> </tr> <tr> <td width="159" bgcolor="#FFCC66">Part Description:</td> <td width="373" bgcolor="#CCCCCC"><input name="ProdDesc" type="text" id="ProdDesc"></td> </tr> <tr> <td bgcolor="#FFCC66">Amount Consumed: </td> <td bgcolor="#CCCCCC"><input name="Consumed" type="int" id="Consumed"></td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit Modifications" /></td> </tr> </table> </form> </body> </html> I believe the value is being pulled but I cannot tell. Here is the PHP code for the work required: <?php // Connect to mysql database $con = mysql_connect("localhost","user","password") or die('Connection: ' . mysql_error());; mysql_select_db("logdata", $con) or die('Database: ' . mysql_error()); mysql_select_db("logdata", $con); // Insert form values into database $copy = mysql_fetch_array(mysql_query("SELECT * FROM `SNAInv` WHERE `ProdNum`= '$_POST[ProdNum]'")) or die(mysql_error()); // ^^ SELECT THE DATA TO BE COPIED ^^ $sqlrun = mysql_query("UPDATE `SNAInv` SET `QtyOnHand` = `$copy[QtyOnHand]` - `". $_POST[Consumed] ."` WHERE `ProdNum` = `$_POST[ProdNum]`"); $sql = @mysql_query("INSERT INTO `SNAInvHist` (`ProdNum`, `ProdDesc`, `QtyOnHand`, `Consumed`, `RecvDate`, `ConSumDate`) VALUES ('" . $copy['ProdNum'] . "', '" . $copy['ProdDesc'] . "', '" . $sqlrun['QtyOnHand'] . "', '". $_POST[Consumed] ."', '". $copy[RecvDate] ."', Now())") or die(mysql_error()); echo "Inventory For Part Number:\n".$copy[ProdNum]." has been modified and a Transaction has been recorded "; echo "<br> new Quantity is:\n".$sqlrun[QtyOnHand].""; mysql_close($con); ?> <p><a href="http://192.168.1.106/sna/snainvmod.html">Return to Manage Inventory Control</a></p> Everything works but the only thing not working is the subtraction part. Each table has the transaction posted but a big fat "0" is posted in the quantity field on the SNAInvHist table and the QTY field in SNAInv is the same as it was. What am I missing? Thanks, Texman Link to comment https://forums.phpfreaks.com/topic/107566-i-cannot-see-the-problem-in-subtracting-a-quantity/ Share on other sites More sharing options...
Prismatic Posted May 28, 2008 Share Posted May 28, 2008 Give this a try, <?php // Connect to mysql database $con = mysql_connect("localhost","user","password") or die('Connection: ' . mysql_error());; mysql_select_db("logdata", $con) or die('Database: ' . mysql_error()); mysql_select_db("logdata", $con); $copy = mysql_fetch_array(mysql_query("SELECT * FROM `SNAInv` WHERE `ProdNum`= '". $_POST['ProdNum'] ."'")) or die(mysql_error()); $sqlrun = mysql_query("UPDATE `SNAInv` SET `QtyOnHand` = `". $copy['QtyOnHand'] ."` - `". $_POST['Consumed'] ."` WHERE `ProdNum` = `". $_POST['ProdNum'] ."`"); $sql = @mysql_query("INSERT INTO `SNAInvHist` (`ProdNum`, `ProdDesc`, `QtyOnHand`, `Consumed`, `RecvDate`, `ConSumDate`) VALUES ('" . $copy['ProdNum'] . "', '" . $copy['ProdDesc'] . "', '" . $sqlrun['QtyOnHand'] . "', '". $_POST[Consumed] ."', '". $copy[RecvDate] ."', Now())") or die(mysql_error()); echo "Inventory For Part Number:\n" .$copy['ProdNum'] ." has been modified and a Transaction has been recorded "; echo "new Quantity is:\n". $sqlrun['QtyOnHand'] .""; mysql_close($con); ?> And it makes it easier for us to read your code if you put it inside code tags Link to comment https://forums.phpfreaks.com/topic/107566-i-cannot-see-the-problem-in-subtracting-a-quantity/#findComment-551359 Share on other sites More sharing options...
texmansru47 Posted May 28, 2008 Author Share Posted May 28, 2008 I will give that a try... Sorry about missing the code tags... I will try to catch that next time. Texman Link to comment https://forums.phpfreaks.com/topic/107566-i-cannot-see-the-problem-in-subtracting-a-quantity/#findComment-551369 Share on other sites More sharing options...
texmansru47 Posted May 28, 2008 Author Share Posted May 28, 2008 Same issue. the main QTY in SNAInv still the same and no QTY in the history table either. Completely baffling for something to be so easy. Link to comment https://forums.phpfreaks.com/topic/107566-i-cannot-see-the-problem-in-subtracting-a-quantity/#findComment-551373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.