xaznbabyx Posted September 5, 2015 Share Posted September 5, 2015 (edited) Im getting a parse error Parse error: syntax error, unexpected ')' in /students/schow11/public_html/cs130a/hw2.php on line 13 How do i calculate this equation? <?php // Get the values from $_POST $loan = $_POST["loanamount"]; $interest = $_POST["interest"]; $months = $_POST["months"]; // Calculate the monthly payment function pmt ($interest, $months, $loan) { $months = $months; $interest = $interest / 12; error--->$amount = $loan * $interest * pow((1 + $interest), $months,) / (1 - pow((1 + $interest), $months)); } $amount = pmt ($interest, $loan, $months) echo "Your monthly carpayment will be;" . round($amount, 2 . " a month, for " . $months . "months"; ?> html <!DOCTYPE html> <html> <head> <title>Homework 3</title> </head> <body> <div> <p> Fill out this form to calculate monthly car payment</p> <form method="post" action="hw2test.php"></form> <p>Loan Amount: <input type="text" name="loan" size="5" /></p> <p>Interest Rate: <input type="text" name="rate" size="5" /></p> <p>Number of Month: <input type="text" name="month" size="5" /></p> <input type="submit" name="submit" value="Caculate" /> </div> </body> </html> Edited September 5, 2015 by xaznbabyx Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 5, 2015 Share Posted September 5, 2015 You're using a pow function to calculate a payment amount? Seems odd. The error is the extra comma in your first pow call. Quote Link to comment Share on other sites More sharing options...
xaznbabyx Posted September 5, 2015 Author Share Posted September 5, 2015 my teacher wants us to use the pow Assignment 2For this assignment, you are going to write a form that will allow someone to calculate their monthly payment for a car loan. Consider the following: The first page should contain a form with three text boxes, to allow the student to enter the following values:Total amount of loan Interest Rate Number of months The second page should calculate the monthly payment according to the following formula: For example, for a loan amount of $18000, an interest rate of 4.9%, and 60 months, the payment should be $338.86 Your second PHP page will need to use the built-in function pow(). The Rate used in the formula above should be the interest rate expressed as a decimal (i.e., 0.049, not 4.9) A person filling in the form can be expected to just enter numbers in the text boxes, no symbols (i.e., no $ or %). Do not worry about error checking for this. Consider using the printf function or the round function to format your payment amount to two decimal places. Quote Link to comment Share on other sites More sharing options...
xaznbabyx Posted September 5, 2015 Author Share Posted September 5, 2015 anyways thank you that fixed the parse error. Im getting another error for echo Parse error: syntax error, unexpected 'echo' (T_ECHO) in /students/schow11/public_html/cs130a/hw2.php on line 17 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 5, 2015 Share Posted September 5, 2015 Since this is homework I'll simply tell you that you are missing a semi. Basic mistake - happens all the time. Quote Link to comment Share on other sites More sharing options...
xaznbabyx Posted September 5, 2015 Author Share Posted September 5, 2015 Thank you so much. I found out what I was missing and im getting this error Notice: Undefined index: loan in /students/schow11/public_html/cs130a/hw2.php on line 4 Notice: Undefined index: interest in /students/schow11/public_html/cs130a/hw2.php on line 5 Notice: Undefined index: months in /students/schow11/public_html/cs130a/hw2.php on line 6 Warning: Division by zero in /students/schow11/public_html/cs130a/hw2.php on line 13 Your monthly carpayment will be;0 a month, for months <?php // Get the values from $_POST $loan = $_POST["loan"]; $interest = $P_POST["interest"]; $months = $_POST["months"]; and warning for this $amount = $loan * $interest * pow((1 + $interest), $months) / (1 - pow((1 + $interest), $months)); Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 5, 2015 Share Posted September 5, 2015 To become a programmer you have to have an eye for detail. Look carefully at your lines and you will see your error. As for the div by zero - perhaps you should check the incoming parms to your functions to be sure that they are valid or simply check the values to be used in your calc before using them. Quote Link to comment Share on other sites More sharing options...
xaznbabyx Posted September 5, 2015 Author Share Posted September 5, 2015 (edited) Thank you i will look into it and see what I did wrong. Edited September 5, 2015 by xaznbabyx Quote Link to comment Share on other sites More sharing options...
xaznbabyx Posted September 5, 2015 Author Share Posted September 5, 2015 I don't get what am I suppose to do to get rid of the unidentified index? // Get the values from $_POST $loan = $_POST["loan"]; $interest = $_POST["interest"]; $months = $_POST["months"]; Notice: Undefined index: interest in /students/schow11/public_html/cs130a/hw2.php on line 13 Notice: Undefined index: months in /students/schow11/public_html/cs130a/hw2.php on line 14 Notice: Undefined variable: loan in /students/schow11/public_html/cs130a/hw2.php on line 24 Your monthly car payment will be;0 a month, for months Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted September 5, 2015 Share Posted September 5, 2015 Your form names and $_POST keys have to match Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 6, 2015 Share Posted September 6, 2015 I dont' see these new lines in your previous code posting (which needs to be posted properly next time!). Have you changed things? And as QOC says - names need to match. Quick lesson: The name attributes of input elements are what you need to look for in your $_POST array upon receiving the submit from the client. That's the connection. Quote Link to comment Share on other sites More sharing options...
gizmola Posted September 6, 2015 Share Posted September 6, 2015 Quick and effective debugging tool for these types of problems: var_dump($_POST); Quote Link to comment Share on other sites More sharing options...
xaznbabyx Posted September 6, 2015 Author Share Posted September 6, 2015 It works now! Thank you, you guys! Someone told me to place if (!isset ($_POST['loan'])) and it works. But now my submit button isn't working. When I calculate the form it gives me this. http://hills.ccsf.edu/~schow11/cs130a/hw2.html http://hills.ccsf.edu/~schow11/cs130a/hw2.php Notice: Undefined variable: loan in /students/schow11/public_html/cs130a/hw2.php on line 28 Your monthly car payment will be;0 a month, for 60months <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Homework 2</title> </head> <body> <pre> <p>Fill out this form to calculate monthly car payment</p> <form method="post" action="hw2.php" > <p>Loan Amount: <input type="text" name="loan" size="5" /></p> <p>Interest Rate: <input type="text" name="interest" size="5" /></p> <p>Number of Month: <input type="text" name="months" size="5" /></p> <p><input type="submit" value="Calculate"></p> </form> <?php if (!isset ($_POST['loan'])) // Get the values from $_POST $loan = 18000; $interest = 0.049; $months = 60; $amount = 338.86; function pmt($loan, $interest, $months) { $amount = $loan * $interest/12 * pow((1 + $interest/12), $months) / (pow((1 + $interest/12), $months - 1)); return $amount; } $amount = pmt($loan, $interest, $months); print "Your monthly car payment will be;" . round($amount,2) . " a month, for " . $months . "months"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.