Page 1 of 1

PHP Addition On Mail Form

Posted: Thu Dec 04, 2008 1:40 pm
by cedartree
hi there.
i have a form in which someone fills in their expense information,
and when they submit the information, it gets e-mailed.
i would like to use the $addition feature in order to total out the information so that I don't have to manually calculate them every time.
I would also like to subtract the difference between Income information VS Expense information.
This is what I have (everything works except for the math part, so i will leave out the unnecessary code):

Code: Select all

 
$total_contents .=  "Groceries/Supplies         : " . $_POST['GroceriesSupplies'] . "\n\n";
$total_contents .=  "Day Care        : " . $_POST['DayCare'] . "\n\n";
$total_contents .=  "Medical         : " . $_POST['Medical'] . "\n\n";
$total_contents .=  "TOTAL EXPENSES: " . $_POST [$addition = 'GroceriesSupplies + DayCare + Medical'] . "\n\n";
 

if you would like i can also e-mail you the php file. Thanks in advance.

Re: PHP Addition On Mail Form

Posted: Thu Dec 04, 2008 3:01 pm
by Reviresco
Not sure what you mean by "$addition feature", but assuming the $_POST variables contain numbers (sums of money):

Code: Select all

$total_expenses = $_POST['GroceriesSupplies'] + $_POST['DayCare'] + $_POST['Medical'] ;
Do the same with your income information. To find the difference:

Code: Select all

$difference = $total_income - $total_expenses;

Re: PHP Addition On Mail Form

Posted: Thu Dec 04, 2008 4:17 pm
by guygk

Code: Select all

$total_contents = NULL;
$total_contents .=  "Groceries/Supplies         : " . $_POST['GroceriesSupplies'] . "\n\n";
$total_contents .=  "Day Care        : " . $_POST['DayCare'] . "\n\n";
$total_contents .=  "Medical         : " . $_POST['Medical'] . "\n\n";
$total_contents .=  "TOTAL EXPENSES: " . (int)$_POST['GroceriesSupplies ']+(int)$_POST['DayCare']+(int)$_POST['Medical'] . "\n\n";

Re: PHP Addition On Mail Form

Posted: Fri Dec 05, 2008 10:41 am
by cedartree
Let's say I need to take an Annual amount and divide it by 12, and add that number to my formula. Should it look like this: ?

Code: Select all

 
$total_contents .=  "TOTAL EXPENSES: " . (int)$_POST['GroceriesSupplies ']+(int)$_POST['DayCare']+(int)$_POST['Medical']+(int)$_POST['AnnualPropertyTaxes']/12 . "\n\n";