Note that there are some explanatory texts on larger screens.

plurals
  1. POcalculating percentages in form processing
    primarykey
    data
    text
    <p>I have a simple calculator form which asks for basic budget information.</p> <p>User Name, Paycheck 1 amount, Paycheck 2 amount, rent, utilities.....</p> <p>Somehow I need to calculate all the expense fields individually as a percentage of the total income. I'm just not sure how to do this. I have gone through a ton of tutorials and none of them worked even with the source files. </p> <p>Here's my processing php. Sure could use a push in the right direction. Thanks!</p> <pre><code> &lt;?php if ($_POST['sum1'] == "yes") { $name = $_POST['name']; $month = $_POST['month']; $year = $_POST['year']; $pay1 = $_POST['pay1']; $pay2 = $_POST['pay2']; $other1 = $_POST['other1']; $other2 = $_POST['other2']; $rent = $_POST['rent']; $repair = $_POST['repair']; $utility = $_POST['utility']; $invest = $_POST['invest']; $insure = $_POST['insure']; $groceries = $_POST['groceries']; $student = $_POST['student']; $travel = $_POST['travel']; $ccard1 = $_POST['ccard1']; $ccard2= $_POST['ccard2']; $cell = $_POST['cell']; $cable = $_POST['cable']; $misc1 = $_POST['misc1']; $misc2 = $_POST['misc2']; $ttl_inc = $pay1+$pay2+$other1+$other2; $ttl_exp = $rent+$repair+$utility+$invest+$insure+$travel+$ccard1+$ccard2+$cell+$cable+$misc1+$misc2+$student+$groceries; $total = $pay1+$pay2+$other1+$other2-$rent-$repair-$utility-$invest-$insure-$travel-$ccard1-$ccard2-$cell-$cable-$misc1-$misc2-$student-$groceries; echo "&lt;h2&gt;Budget Recap Prepared For {$name} For Period: {$month} {$year}&lt;/h2&gt; &lt;br /&gt;"; echo "&lt;br /&gt;"; echo "&lt;h3&gt;Income&lt;/h3&gt; &lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Pay Period 1: $ {$pay1} &lt;br /&gt;"; echo "Pay Period 2: $ {$pay2} &lt;br /&gt;"; echo "Other Income 1: $ {$other1} &lt;br /&gt;"; echo "Other Income 2: $ {$other2} &lt;br /&gt;"; echo "&lt;strong&gt;TOTAL INCOME: $ {$ttl_inc} &lt;/strong&gt;&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "&lt;h3&gt;Expenses&lt;/h3&gt; &lt;br /&gt;"; echo "&lt;br /&gt;"; echo "Rent: $ {$rent} &lt;br /&gt;"; echo "Utilities: $ {$utility} &lt;br /&gt;"; echo "Groceries: $ {$groceries} &lt;br /&gt;"; echo "Insurance: $ {$insure} &lt;br /&gt;"; echo "Credit Card 1: $ {$ccard1} &lt;br /&gt;"; echo "Credit Card 2: $ {$ccard2} &lt;br /&gt;"; echo "Repairs/Maintenance: $ {$repair} &lt;br /&gt;"; echo "Savings/Investments: $ {$invest} &lt;br /&gt;"; echo "Student Loans: $ {$student} &lt;br /&gt;"; echo "Transportation: $ {$travel} &lt;br /&gt;"; echo "Cell/Mobile Phone: $ {$cell} &lt;br /&gt;"; echo "Cable/Internet/Other: $ {$cable} &lt;br /&gt;"; echo "Other Expenses 1: $ {$misc1} &lt;br /&gt;"; echo "Other Expenses 2: $ {$misc2} &lt;br /&gt;"; echo "&lt;strong&gt;TOTAL EXPENSES: $ - {$ttl_exp} &lt;/strong&gt;&lt;br /&gt;"; echo "&lt;br /&gt;"; echo "&lt;strong&gt;NET INCOME FOR {$month} {$year} : $ {$total} &lt;/strong&gt;&lt;br /&gt;"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload