Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP/HTML calculation

    Hi,
    I am making a little Purchase order entry form for a mysql database.
    I have the form and can submit everything just fine, Only thing is I can't seem to figure out how to make a calculation on various text boxes. I need to make a sum of a group of boxes, calculate taxes etc... Anyone able to point me to some sample code of a way to make arthimatic functions on the contnts of box1 and box 2 and put them in box 3. I will only be inserting box 3 into the database and that part works already.

  • #2
    Regular Coder
    Join Date
    Nov 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am going to insert the code I have so far for the Purchase order page.
    Code:
    <html>
    <body><form action="library/insert.php" method="post">
      <table width="665" height="68" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th width="407" rowspan="2" scope="col"><img src="images/soileng-logo.jpg" width="345" height="65" align="left"></th>
          <th width="90" height="34" scope="col"><div align="right">PO Number: </div></th>
          <th width="168" scope="col">&nbsp;</th>
        </tr>
        <tr>
          <td><div align="right"><strong>Date</strong>:</div></td>
          <td><div align="center">
            <input name="date_year" type="text" value="YYYY" size="4" maxlength="4" />
            /
            <input name="date_month" type="text" value="MM" size="2" maxlength="2" />
            /
      <input name="date_day" type="text" value="DD" size="2" maxlength="2" />
          </div></td>
        </tr>
      </table>
      <br>
      <table width="667" height="197" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th colspan="9" scope="col"><div align="left">PO Requested By</div></th>
        </tr>
        <tr>
          <td width="267">First Name:      
          <input name="staff_firstname" type="text" size="20" maxlength="20" /></td>
          <td colspan="3">Last Name:
          <input name="staff_lastname" type="text" size="20" maxlength="20" /></td>
          <td width="107" colspan="5">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3">Department:
          <input name="staff_department" type="text" size="30" maxlength="30" /></td>
          <td>&nbsp;</td>
          <td colspan="5">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3"><strong>Vendor Information </strong></td>
          <td width="186">&nbsp;</td>
          <td colspan="5">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="9">Company:
          <input name="vendor_company" type="text" size="50" maxlength="50" /></td>
        </tr>
        <tr>
          <td colspan="9">Address1:
          <input name="vendor_address1" type="text" size="50" maxlength="50" /></td>
        </tr>
        <tr>
          <td colspan="9">Address2:
          <input name="vendor_address2" type="text" size="50" maxlength="50" /></td>
        </tr>
        <tr>
          <td colspan="2">City:      
          <input name="vendor_city" type="text" size="40" maxlength="50" /></td>
          <td colspan="7">Postal Code:
          <input name="vendor_postalcode" type="text" size="10" maxlength="10" /></td>
        </tr>
        <tr>
          <td colspan="2">Province:
          <input name="vendor_province" type="text" size="20" maxlength="20" /></td>
          <td colspan="7">Country:
          <input name="vendor_country" type="text" size="20" maxlength="20" /></td>
        </tr>
        <tr>
          <td colspan="2">Phone Number:
          <input name="vendor_phonenum" type="text" size="20" maxlength="20" /></td>
          <td colspan="7">Fax Number:
          <input name="vendor_faxnum" type="text" size="20" maxlength="20" /></td>
        </tr>
      </table>
      <p><strong>  Purchase Order Details:</strong></p>
      <table width="670" border="1">
        <tr>
          <th width="392" scope="col">Item Desription </th>
          <th width="100" scope="col">Unit Cost </th>
          <th width="50" scope="col">Qty</th>
          <th width="100" scope="col">Extended Cost </th>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3"><div align="right"><strong>Sub Total : </strong></div></td>
          <td><div align="right">
            <input name="subtotal" type="text" size="15" maxlength="15" />
          </div></td>
        </tr>
        <tr>
          <td colspan="3"><div align="right"><strong>Shipping: </strong></div></td>
          <td><div align="right">
            <input name="shipping" type="text" size="15" maxlength="15" />
          </div></td>
        </tr>
        <tr>
          <td colspan="3"><div align="right"><strong>GST: </strong></div></td>
          <td><div align="right">
            <input name="gst" type="text" size="15" maxlength="15" />
          </div></td>
        </tr>
        <tr>
          <td colspan="3"><div align="right"><strong>PST: </strong></div></td>
          <td><div align="right">
            <input name="pst" type="text" size="15" maxlength="15" />
          </div></td>
        </tr>
        <tr>
          <td colspan="3"><div align="right"><strong>Total: </strong></div></td>
          <td><div align="right">
            <input name="total" type="text" size="15" maxlength="15" />
          </div></td>
        </tr>
      </table>
      <p align="left">
      Description:
        <input name="podescription" type="text" value="" size="85" maxlength="100">
        <br>
        referencenumber:
        <input type="text" name="referencenumber" />
        paidstatus:
        <input type="text" name="paidstatus" />
      </p>
      <p align="left">
        <input name="Button" type="button" value="Calculate Taxes and Total" />
        <input name="submit" type="submit" value="Submit and Print" />
        <input name="submit2" type="reset" value="Clear PO / Start Over" />
      </p>
    </form></body>
    </html>

  • #3
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    Here is an example.

    PHP Code:
    // get posted values 
    $item1 floatval $_POST['item1'] );
    $item2 floatval $_POST['item2'] );
    $item3 floatval $_POST['item3'] );
    $item4 floatval $_POST['item4'] );
    $item5 floatval $_POST['item5'] );

    // calculate total value.
    $total $item1 $item2 $item3 $item4 $item5;
    // calculate VAT
    $total $total 0.175 $total;

    // do other operations...and update database. 
    Note: I would recommend that you have a look at osCommerece. it is an on-line e-commerce solution....and it might save you a lot of time coding and making sure that your code is secure and is performing the correct calculations.

    good luck.
    Ess

  • #4
    Regular Coder
    Join Date
    Nov 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahh ok thanks, how would I embed that into a button and how do I put the $total value back into a text box?

    Do the variables not need to be assigned?

    Maybew a quick sample code with a page with 3 text boxes,
    userput1 userinput2 press button puts total into box 3


  •  

    Posting Permissions

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