Jump to content

[SOLVED] This one's too easy (except for me)


matthewst

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/61005-solved-this-ones-too-easy-except-for-me/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.