[EMAIL PROTECTED] wrote:
Hi all, A PHP question to ask: I am using PHP to do a calculation of the total of
fields where user actually input the amount into the text field and I will
calculate the TOTAL from the fields as well as the GST.
Wonder how should I go about doing that?


I did something like :
           $total = $_POST["field 1"] + $_POST["field 2"] + $_POST["field 3"];
           $total = number_format($total, 2, ".", " ");
           echo "$$total<br>";
           echo "$".$total."<br>";

but it wasn't successful.

What do you mean it wasn't successful? What did you get on the screen? Are you sure that the fields are being referenced correctly? Something like this would use some error checking :


$total  = 0;
$errors = "";
if($_POST["field 1"])
{
   $total += intval($_POST["field 1"]);
} else { $errors .= "Field 1 not entered"; }
if($_POST["field 2"])
{
   $total += intval($_POST["field 2"]);
} else { $errors .= "Field 2 not entered"; }
if($_POST["field 3"])
{
   $total += intval($_POST["field 3"]);
} else { $errors .= "Field 3 not entered"; }
if ($errors != "")
{
   echo "Errors : ".$errors;
}
$total = number_format($total, 2, '.', '');
echo "Total is \$ ".$total;


-- Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to