Tim,

It is not necessary to retrieve your values using $HTTP_POST_VARS, the
variables can be referred to by their name, e.g $hit_955 so in PART 1 it
appears that you are intialising everything that was passed from the select
page to 0. All you need to do is initialise your counters.

PART ONE:
<?

$SubTotal = 0;
$FormattedSubTotal = 0;
$Total = 0;
$FormattedTotal = 0;

$PST = 1.08;
$GST = 1.07;
$CalcPST = 0;
$CalcGST = 0;
$FormattedPST = 0;
$FormattedGST = 0;
?>

I would say that the 3 items that you are getting values for are spelt
incorrectly in that initialisation section and are not getting zeroed.

The problem is that the missing values will be a null string and your
calculation will fail.

For each value passed you will need to do a test and set to 0 if the variable
does not exist e.g.:-

if(!$hit_955) {
    $hit_955 = 0;
}

etc...

Have fun,

Chris

Tim Thorburn wrote:

> Hi,
>
> I'm creating a very simple script (or so I thought) in which a user can
> select items from a form, the script will take the number values of those
> items and do two things: display the names of the items selected, and add
> the items together and give the user a total price including taxes.
>
> In my form, I use the following syntax:
> <input type="checkbox" name="hit_955" value="14.72">
>
> The form is then sent using the POST method.
>
> I then retrieve the values using the following syntax:
> $hit_955 = $HTTP_POST_VARS["hit_955"];
>
> All together there are 14 items a user can choose - for testing purposes, I
> chose all items.  The script would only display and add the first, second,
> and tenth items.  All others are ignored.
>
> Here is the script - its broken into three parts - the first part is
> collecting the information - the second part is doing the actual math - and
> the third part displays the item names that the user chose.  Does anyone
> see anything wrong with this script, or have a possible reason why its only
> choosing 3 out of 14 items to work with?
>
> PART ONE:
> <?
>
> $SubTotal = 0;
> $FormattedSubTotal = 0;
> $Total = 0;
> $FormattedTotal = 0;
>
> $PST = 1.08;
> $GST = 1.07;
> $CalcPST = 0;
> $CalcGST = 0;
> $FormattedPST = 0;
> $FormattedGST = 0;
>
> $nokia252c = 0;
> $battery = 0;
> $hit_955 = 0;
> $hit_965 = 0;
> $nok_cbl_7 = 0;
> $nok_lch_6rpd = 0;
> $nok_cgh10 = 0;
> $nok_lch9 = 0;
> $belt_252 = 0;
> $nokia_0261670 = 0;
> $s_nok_0261669 = 0;
> $nok_mbc_3k = 0;
> $nok_cark_89 = 0;
> $nok_cark_90 = 0;
>
> $nokia252c = $HTTP_POST_VARS["nokia252c"];
> $battery = $HTTP_POST_VARS["battery"];
> $hit_955 = $HTTP_POST_VARS["hit_955"];
> $hit_965 = $HTTP_POST_VARS["hit_965"];
> $nok_cbl_7 = $HTTP_POST_VARS["nok_cbl_7"];
> $nok_lch_6rpd = $HTTP_POST_VARS["nok_lch_6rpd"];
> $nok_cgh10 = $HTTP_POST_VARS["nok_cgh10"];
> $nok_lch9 = $HTTP_POST_VARS["nok_lch9"];
> $belt_252 = $HTTP_POST_VARS["belt_252"];
> $nokia_0261670 = $HTTP_POST_VARS["nokia_0261670"];
> $s_nok_0261669 = $HTTP_POST_VARS["s_nok_0261669"];
> $nok_mbc_3k = $HTTP_POST_VARS["nok_mbc_3k"];
> $nok_cark_89 = $HTTP_POST_VARS["nok_cark_89"];
> $nok_cark_90 = $HTTP_POST_VARS["nok_cark_90"];
>
> ?>
>
> PART TWO:
> <?
> $SubTotal = $nokia252c + $battery + $hit_955 + $hit_965 + $nok_cbl_7 +
> $nok_lch_6rpd + $nok_cgh10 + $nok_lch9 + $belt_252 + $nokia_0261670 +
> $s_nok_0261669 + $nok_mbc_3k + $nok_cark_89 + $nok_cark_90;
> $CalcPST = ($SubTotal * $PST) - $SubTotal;
> $CalcGST = ($SubTotal * $GST) - $SubTotal;
> $Total = $SubTotal + $CalcPST + $CalcGST;
> $FormattedSubTotal = number_format($SubTotal, 2);
> $FormattedPST = number_format($CalcPST, 2);
> $FormattedGST = number_format($CalcGST, 2);
> $FormattedTotal = number_format($Total, 2);
> ?>
>
> PART THREE:
> <? if ($nokia252c > 0)
> {
>    echo "Nokia 252c";
> }
>    else
> {
>    echo "";
> } ?>
>
> Thanks
> -Tim
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

--

Chris Fry
Quillsoft Pty Ltd
Specialists in Secure Internet Services and E-Commerce Solutions
10 Gray Street
Kogarah
NSW  2217
Australia

Phone: +61 2 9553 1691
Fax: +61 2 9553 1692
Mobile: 0419 414 323
eMail: [EMAIL PROTECTED]
http://www.quillsoft.com.au

You can download our Public CA Certificate from:-
https://ca.secureanywhere.com/htdocs/cacert.crt

**********************************************************************

This information contains confidential information intended only for
the use of the authorised recipient.  If you are not an authorised
recipient of this e-mail, please contact Quillsoft Pty Ltd by return
e-mail.
In this case, you should not read, print, re-transmit, store or act
in reliance on this e-mail or any attachments, and should destroy all
copies of them.
This e-mail and any attachments may also contain copyright material
belonging to Quillsoft Pty Ltd.
The views expressed in this e-mail or attachments are the views of
the author and not the views of Quillsoft Pty Ltd.
You should only deal with the material contained in this e-mail if
you are authorised to do so.

This notice should not be removed.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to