For my course project I have to create a web page where users can insert there income and expense information into the form and then get an output that tells them what their total income is, their total expenses, how much they will have left after paying expenses, and then it tells the user what percentage of their income and expenses each expense actually is.
I have been really proud of myself, because I wrote a code that does exactly what it’s supposed to and it seems to work just fine. This week, however, I have to take that output page and give the user a way to print the information and/or email the information to themselves. I want to create buttons from images (images/print.png) and (images/email.png) that do that. But I can’t find any examples that help me get their using this project.
Is there a simple string of script that will send my html out to the printer and email? Or do I need to create a new script all together and link the buttons to those scripts? This is my output page as it stands right now:
[php]<?php
// create short variable names; each variable name is reflective of the field it’s assigned to. I have tried to keep my variables under 5-6 letters, so some longer words have been reduced to an abbreviated form (for example maintenance becomes maint, which is the first five letters of the word. Also you maynoticed that utility becomes uutil, which is only four letters, the reason is because I never end an abbreviation with a vowel- it’s a weird compulsion, but it’s one I understand.
$name = $_POST[‘name’];
$email = $_POST[‘email’];
$month = $_POST[‘month’];
$year = $_POST[‘year’];
$pay1 = $_POST[‘pay1’];
$pay2 = $_POST[‘pay2’];
$pay3 = $_POST[‘pay3’];
$pay4 = $_POST[‘pay4’];
$house = $_POST[‘house’];
$util = $_POST[‘util’];
$trans = $_POST[‘trans’];
$ins = $_POST[‘ins’];
$maint = $_POST[‘maint’];
$food = $_POST[‘food’];
$loan = $_POST[‘loan’];
$invest = $_POST[‘invest’];
$cc1 = $_POST[‘cc1’];
$cc2 = $_POST[‘cc2’];
$cell = $_POST[‘cell’];
$media = $_POST[‘media’];
$other1 = $_POST[‘other1’];
$other2= $_POST[‘other2’];
//sets fields taking money amounts to floats, so that they can take real money values
settype ($year, ‘int’);
settype ($pay1, ‘float’);
settype ($pay2, ‘float’);
settype ($pay3, ‘float’);
settype ($pay4, ‘float’);
settype ($house, ‘float’);
settype ($util, ‘float’);
settype ($trans, ‘float’);
settype ($ins, ‘float’);
settype ($maint, ‘float’);
settype ($food, ‘float’);
settype ($loan, ‘float’);
settype ($invest, ‘float’);
settype ($cc1, ‘float’);
settype ($cc2, ‘float’);
settype ($cell, ‘float’);
settype ($media, ‘float’);
settype ($other1, ‘float’);
settype ($other2, ‘float’);
?>
$name
";
echo "$email
";
//script for defining the month variable and displaying the outcome
if ($month == "1") {
echo "January ";
} elseif ($month == "2") {
echo "February ";
} elseif ($month == "3") {
echo "March ";
} elseif ($month == "4") {
echo "April ";
} elseif ($month == "5") {
echo "May ";
} elseif ($month == "6") {
echo "June ";
} elseif ($month == "7") {
echo "July ";
} elseif ($month == "8") {
echo "August ";
} elseif ($month == "9") {
echo "September ";
} elseif ($month == "10") {
echo "October ";
} elseif ($month == "11") {
echo "November ";
} elseif ($month == "12") {
echo "December ";
} else {
echo "Month Not Chosen"; }
echo "$year
"; //echos the entry for the year.
//adds income fields
$income = 0;
$income = $pay1 + $pay2 + $pay3 + $pay4;
printf ("
Total Income is $%.2f
", $income);
//adds expense fields
$expenses = 0;
$expenses = $house + $util + $trans + $ins + $maint + $food + $loan + $invest + $cc1 + $cc2 + $cell + $media + $other1 + $other2;
printf ("Total Expenses are $%.2f
", $expenses);
//subtracts expense from income
$outlook = 0;
$outlook = $income - $expenses;
printf ("Total pocket for the month is $%.2f
", $outlook);
//creates projects on expense and income totals for each expense, rounds to the nearest tenth place
echo '
Expense Projections:
';$rent1= 0;
$rent2= 0;
$rent1= round($house / $income * 100,2);
$rent2= round($house / $expenses * 100,2);
echo “
- ”; //begins an unordered list
- Rent/Mortgage account for $rent1% of the total income and $rent2% of the total expenses
- Utilities account for $util1% of the total income and $util2% of the total expenses
- Transportation costs account for $trans1% of the total income and $trans2% of the total expenses
- Insurance costs account for $ins1% of the total income and $ins2% of the total expenses
- Saving for maintenance costs for a house and/or car account for $maint1% of the total income and $maint2% of the total expenses
- Grocery spending accounts for $food1% of the total income and $food2% of the total expenses
- Monthly loan payments account for $loan1% of the total income and $loan2% of the total expenses
- This month $invest1% of the total income and $invest2% of the total expenses was spent on investments
- The first credit card accounts for $cc11% of the total income and $cc12% of the total expenses
- The second credit card accounts for $cc21% of the total income and $cc22% of the total expenses
- Credit card debt accounts for $ccx1% of the total income and $ccx2% of the total expenses
- Mobile phone service accounts for $cell1% of the total income and $cell2% of the total expenses
- Entertainment costs (like cable and internet bills, for example) account for $media1% of the total income and $media2% of the total expenses
- The first miscellaneous expense accounts for $other11% of the total income and $other12% of the total expenses
- The second miscellaneous expense accounts for $other21% of the total income and $other22% of the total expenses
- Your total miscellaneous spending expense accounts for $otherx1% of the total income and $otherx2% of the total expenses
echo “
”;
$util1= 0;
$util2= 0;
$util1= round($util / $income * 100,2);
$util2= round($util / $expenses * 100,2);
echo “
”;
$trans1= 0;
$trans2= 0;
$trans1= round($trans / $income * 100,2);
$trans2= round($trans / $expenses * 100,2);
echo “
”;
$ins1= 0;
$ins2= 0;
$rent1= round($ins / $income * 100,2);
$rent2= round($ins / $expenses * 100,2);
echo “
”;
$maint1= 0;
$maint2= 0;
$maint1= round($maint / $income * 100,2);
$maint2= round($maint / $expenses * 100,2);
echo “
”;
$food1= 0;
$food2= 0;
$food1= round($food / $income * 100,2);
$food2= round($food / $expenses * 100,2);
echo “
”;
$loan1= 0;
$loan2= 0;
$loan1= round($loan / $income * 100,2);
$loan2= round($loan / $expenses * 100,2);
echo “
”;
$invest1= 0;
$invest2= 0;
$invest1= round($invest / $income * 100,2);
$invest2= round($invest / $expenses * 100,2);
echo “
”;
//To demonstrate I’m putting thought into my budget tracker, and create a more accurate projection, I combined credit cards 1 and 2 into one variable, ccx, and calculated the percentage of the total credit card debt as well as each individual card.
$cc11= 0;
$cc12= 0;
$cc11= round($cc1 / $income * 100,2);
$cc12= round($cc1 / $expenses * 100,2);
echo “
”;
$cc21= 0;
$cc22= 0;
$cc21= round($cc2 / $income * 100,2);
$cc22= round($cc2 / $expenses * 100,2);
echo “
”;
$ccx= 0;
$ccx= $cc1 + $cc2;
$ccx1= round($ccx / $income * 100,2);
$ccx2= round($ccx / $expenses * 100,2);
echo “
”;
//and then I go back figuring up the fields like I did in the early part of the projections
$cell1= 0;
$cell2= 0;
$cell1= round($cell / $income * 100,2);
$cell2= round($cell / $expenses * 100,2);
echo “
”;
$media1= 0;
$media2= 0;
$media1= round($media / $income * 100,2);
$media2= round($media / $expenses * 100,2);
echo “
”;
$other11= 0;
$other12= 0;
$other11= round($other1 / $income * 100,2);
$other12= round($other1 / $expenses * 100,2);
echo “
”;
$other21= 0;
$other22= 0;
$other21= round($other2 / $income * 100,2);
$other22= round($other2 / $expenses * 100,2);
echo “
”;
//I decided to create a total miscellaneous spending calculation
$otherx= 0;
$otherx= $other1 + $other2;
$otherx1= round($otherx / $income * 100,2);
$otherx2= round($otherx / $expenses * 100,2);
echo “
”;
echo “
- ”; //kills the unordered list
?>
This is my output page, along with some basic notation to show you what I was thinking when I wrote something. I know a lot of people aren’t into closing php tags, but they are required for the course work, so that’s out of my hands. I’m not trying to get fancy, just something simple, basic, and functional.
Thanks i advance for anyone who can give me some pointers on this…