PHP Addition On Mail Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cedartree
Forum Newbie
Posts: 10
Joined: Thu Dec 04, 2008 1:35 pm

PHP Addition On Mail Form

Post 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.
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: PHP Addition On Mail Form

Post 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;
guygk
Forum Newbie
Posts: 9
Joined: Thu Dec 04, 2008 4:06 pm

Re: PHP Addition On Mail Form

Post 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";
cedartree
Forum Newbie
Posts: 10
Joined: Thu Dec 04, 2008 1:35 pm

Re: PHP Addition On Mail Form

Post 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";
 
Post Reply