Jump to content
Larry Ullman's Book Forums

Chapter 4 Calculation Confusion!


Recommended Posts

Hello :D

I love Mr. Ullman's books!

98% of the time its easy to understand and learn.

 

However I think this might be an error from printing or just a older php thing or something on my side.

 

OK in chapter 4 pages 74-80 you have to create the sales cost calculator.

Well when you get down towards the end of making the calculations part in handle_calc.php it asks you to add $payments = $_POST['payments']; as the payment part. However I get errors after I get it all done. The errors say the following!

 

error1.png

 

 

After reading and going through the book I took out the s in payments in $payments = $_POST['payments']; so in the end it ends up looking like this $payments = $_POST['payment']; after I get rid of that s it works fine. Am i missing something or did I not add another code yet. here is my code for the file its the handle_calc.php. in a spoiler tag/code tag!

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd%22>"]http://www.w3.org/TR...nsitional.dtd">[/url]
<html xmlns="[url="http://www.w3.org/1999/xhtml%22>"]http://www.w3.org/1999/xhtml">[/url]
<head>
<!--

9/5/2012
4.2 - Creating the script
-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Product Cost Calculator</title>
<style type="text/css" media="screen">
.numbers {font-weight: bold; }
</style>
</head>

<body>
<?php // Script 4.2 - handle_calc.php
/* This script takes values from calculator.html and performs total cost and monthly payment calculations. */

// Address error handling, if you want.
ini_set ('display_errors', 1);
error_reporting (E_ALL | E_STRICT);

// Get the values from the $_POST array:
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$discount = $_POST['discount'];
$tax = $_POST['tax'];
$shipping = $_POST['shipping'];
$payments = $_POST['payment'];

// Calculate the total:
$total = $price * $quantity;
$total = $total + $shipping;
$total = $total - $discount;

//Determine the tax rate:
$taxrate = $tax/100;
$taxrate = $taxrate + 1;

//factor in the tax rate:
$total = $total * $taxrate;

//Calculate the monthly payments:
$monthly = $total / $payments;

// Print out the results:
print "<p>You have selected to purchase:<br />
<span class=\"number\">$quantity</span> widget(s) at <br />
$<span class=\"number\">$price</span> price each plus a <br />
$<span class=\"number\">$shipping</span> Shipping cost and a <br />
<span class=\"number\">$tax</span> percent tax rate. <br />
After your $<span class=\"number\">$discount</span> discount, the total cost is
$<span class=\"number\">$total</span>.<br />
Divided over <span class=\"number\">$payments</span> monthly payment, that would be
$<span class=\"number\">$monthly</span> each.</p>";

?>
</body>
</html>

 

 

 

I hope I made sense thank you

 

---edit post----

Oh almost for got

I use Wamp server for my php and everything

didn't like xammp!

I also use the newest version of php, mysql and what not!

Link to comment
Share on other sites

Try making the following change:

 

$payments = $_POST['payment'];

to

$payments = $_POST['payments'];

 

That should work.

 

see it seems I didn't explain myself well!

 

thats what I was trying to explain in my post. I tried that, exactly what the book told me, but it keeps giving me the same error! if I try it without the S it works but why is that?

Link to comment
Share on other sites

 Share

×
×
  • Create New...