SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    amount_add or amount_remove doesn't add or subtract (was "This should be easy")

    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
    Code:
    					<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
    Code:
    $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

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're better of directly substracting/adding the values in your queries:
    Code php:
    $add_amount=(int)$_POST['add_amount']; //or (float)$_POST['add_amount']
    $query_update="UPDATE sr_size SET amount=amount+$add_amount WHERE '$add_thick' = size";
    Saul

  3. #3
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks php_daemon that works like a charm

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oh and, not sure where does $add_thick come from, but you might wanna use mysql_real_escape_string to protect yourself.
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •