matthewst Posted July 20, 2007 Share Posted July 20, 2007 When I put a number in the "amount_add" or "amount_remove" box it simple palces that number in the amount field in my database instead of adding or subtracting it from the previous amount. php page <form name="FormName" action="beta_tester_handler.php" enctype="multipart/form-data" method="post"> </td> </tr> <tr> <td align="center" colspan="2">SR Sizes, Quantity:</td> </tr> <tr> <td align="center">Add SR</td> <td align="center"><select name="add_thick" class="formTextBox" size="1"> <option value="">----Select----</option> <option value="1/4 X 8">1/4 X 8</option> <option value="1/4 X 10">1/4 X 10</option> <option value="1/4 X 12">1/4 X 12</option> <option value="1/4 X 14">1/4 X 14</option> <option value="1/4 X 16">1/4 X 16</option> </select>X<input type="text" class="formSmallTextbox" name="amount_add" size="4"></td> </tr> <tr> <td align="center">Remove SR</td> <td align="center"><select name="remove_thick" class="formTextBox" size="1"> <option value="">----Select----</option> <option value="1/4 X 8">1/4 X 8</option> <option value="1/4 X 10">1/4 X 10</option> <option value="1/4 X 12">1/4 X 12</option> <option value="1/4 X 14">1/4 X 14</option> <option value="1/4 X 16">1/4 X 16</option> </select>X<input type="text" class="formSmallTextbox" name="amount_remove" size="4"></td> </tr> php handler $query="SELECT amount FROM sr_size WHERE '$add_thick' = size"; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { $amount = $row['amount']; } if ($amount_add != "" & $add_thick == "1/4 X 8"){ $add_amount = $amount + $amount_add; $query_update="UPDATE sr_size SET amount='$add_amount' WHERE '$add_thick' = size"; mysql_query($query_update) or die(mysql_error());} if ($amount_remove != "" & $add_thick == "1/4 X 8"){ $remove_amount = $amount - $amount_remove; $query_update="UPDATE sr_size SET amount='$remove_amount' WHERE '$remove_thick' = size"; mysql_query($query_update) or die(mysql_error());} database ______size________________amount _____1/4 X 8___________10 Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted July 20, 2007 Share Posted July 20, 2007 try: amount=(amount+$add_amount) Quote Link to comment Share on other sites More sharing options...
matthewst Posted July 20, 2007 Author Share Posted July 20, 2007 I don't follow. my logic is new amount = old amount + amount being added $add_amount = $amount + $amount_add Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 20, 2007 Share Posted July 20, 2007 I wonder if the problem is that there is an error with your query and you have display_errors off? Anyway, you don't need to retreive the value from the database first. You can save yourself a query and do: $query_update="UPDATE sr_size SET amount= amount +'$add_amount' WHERE '$add_thick' = size"; This sets your amount field to whatever is already in it, plus $add_amount. Quote Link to comment Share on other sites More sharing options...
matthewst Posted July 23, 2007 Author Share Posted July 23, 2007 Thanks GingerBot that did it Thanks to everyone else for all the help 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.