Jump to content

Code producing error message and I can't figure out why


canadian_angel

Recommended Posts

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

        <title>Product Cost</title>

    </head>

    <body>

        <?php // Script 4.5 - handle_calc.php

 

        /*This script takes values from calculator.html and performs

        total cost and monthly payment calculations. */

 

        // Address error handling.

        ini_set ('display_errors', 1);

        error_reporting(E_ALL & ~E_NOTICE);

 

        // In case register_globals is enabled.

        $price = $_POST['price'];

        $quantity = $_POST['quantity'];

        $discount = $_POST['discount'];

        $tax = $_POST['tax'];

        $shipping = $_POST['shipping'];

        $payments = $_POST['payments'];

       

        // Calculate the total

        $total=(($price * $quantity) + $shipping) - $discount;

       

        // Determine the tax rate

        $taxrate = $tax/100;

        $taxrate++;

 

      // Factor in the tax rate.

        $total = $total * $taxrate;

 

      // Calculate the monthly payments.

        $monthly = $total / $payments;

 

        // Apply the proper formatting.

        $total = number_format ($total, 2);

        $monthly = number_format ($monthly, 2);

 

      // Print out the results.

        print "You have selected to purchase:<br />

        <b>$quantity</b> widget(s) at <br />

        $<b>$price</b> price with a <br />

        $<b>$shipping</b> shipping cost and a <br />

        <b>$tax</b> percent tax rate. <br />

        After your $<b>$discount</b> discount, the total cost is

        $<b>$total</b>.<br />

        Divided over <b>$payments</b> monthly payments, that would be $<b>$monthly</b> each.";

 

        ?>

 

    </body>

</html>

Error message:

Warning: Division by zero in C:\AppServ\www\chapter4\handle_calc.php  on line 37

 

You have selected to purchase:

widget(s) at

$ price with a

$ shipping cost and a

percent tax rate.

After your $ discount, the total cost is $0.00.

Divided over monthly payments, that would be $0.00 each.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.