Jump to content

Archived

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

cspgsl

cannot get correct $totalamount

Recommended Posts

Even though it is great to learn it sucks to be new... I really do appreciate the help however !!

My order entry form is at www.php.cedarsprings.cc

It seems to work with one exception, when I order a plan and a toolkit the total order is supposed to include the plan price + the toolkit price + the toolkit setup charge... all + tax.

Thus far the php code returns the correct items sold and calculates the order total for the plans and the toolkits but will not add the appropriate setup charge to the order.

$totalamount includes all of the variables so I just acnnot see what i'm missing.

Again, thanks in advance

[code]
<?php
// create short variable names
$pro = $_POST['pro'];
$comp = $_POST['comp'];
$personal = $_POST['personal'];
$diy = $_POST['diy'];
$host = $_POST['host'];
$qna = $_POST['qna'];
$facts = $_POST['facts'];
$calc = $_POST['calc'];
$news = $_POST['news'];
$setupcomp = $_POST['setupcomp'];
$setuppersonal = $_POST['setuppersonal'];
$setuphost = $_POST['setuphost'];


echo '<p>Your order is as follows: </p>';
$totalqty = 0;
$totalqty = $pro + $comp + $personal + $diy + $host + $qna + $facts + $calc + $news + $setupcomp + $setuppersonal + $setupdiy + $setuphost;
echo 'Items Ordered: '.$totalqty.'<br />';

$totalamount = 0.00;

define('PROPRICE', 1.00);
define('COMPPRICE', 1.00);
define('PERSONALPRICE', 1.00);
define('DIYPRICE', 1.00);
define('HOSTPRICE', 1.00);
define('QNAPRICE', 1.00);
define('FACTSPRICE', 1.00);
define('CALCPRICE', 1.00);
define('NEWSPRICE', 1.00);
define('SETUPCOMPPRICE', 1.00);
define('SETUPPERSONALPRICE', 1.00);
define('SETUPDIYPRICE', 1.00);
define('SETUPHOSTPRICE', 1.00);

$totalamount =     $pro * PROPRICE
                + $comp * COMPPRICE
                + $personal * PERSONALPRICE
                + $diy * DIYPRICE
                + $host * HOSTPRICE                                                                
                + $qna * QNAPRICE
                + $facts * FACTSPRICE                                
                + $calc * CALCPRICE                                
                + $news * NEWSPRICE;                                
                + $setupcomp * SETUPCOMPPRICE;                                
                + $setuppersonal * SETUPPERSONALPRICE;                                
                + $setupdiy * SETUPDIYPRICE;                                
                + $setuphost * SETUPHOSTPRICE;                                



                if( $comp &&  ($qna>0||$facts>0||$calc>0||$news>0))
                    $setupcomp = 1;

                elseif( $personal &&  ($qna>0||$facts>0||$calc>0||$news>0))
                    $setuppersonal = 1;

                elseif( $diy &&  ($qna>0||$facts>0||$calc>0||$news>0))
                    $setupdiy = 1;

                elseif( $host &&  ($qna>0||$facts>0||$calc>0||$news>0))
                    $setuphost = 1;

echo 'Subtotal: $'.number_format($totalamount,2).'<br />';

$taxrate = 0.15; // local salestax is 15%

$totalamount = ($totalamount) * (1 + $taxrate);

echo 'Total including tax: $'.number_format ($totalamount,2).'<br />';                

                if( $totalqty == 0 )
                {
                echo '<font color=red>';
                echo 'You did not order anything! <br />';
                echo '</font>';
                }
                
                if( $pro + $comp + $personal + $diy + $host> 1 )
                {
                echo '<font color=red>';
                echo 'You may only order one hosting plan! <br /> Please press your browsers back button and select the plan you want <br /> Your order cannot be processed<br />';
                echo '</font>';
                }

                if( $pro + $comp + $personal + $diy + $host == 0 )
                {
                echo '<font color=red>';
                echo 'You must order one hosting plan! <br /> Please press your browsers back button and make a selection <br />Your order cannot be processed<br />';
                echo '</font>';
                }

                else
                {
                if ($pro> 0 )
                    echo $pro.' Professional Plan<br />';
                if ($comp> 0 )
                    echo $comp.' Comprehensive Plan<br />';
                if ($personal> 0 )
                    echo $personal.' Personal Plan<br />';
                if ($diy> 0 )
                    echo $diy.' DIY Plan<br />';
                if ($host> 0 )
                    echo $host.' Hosting Only Plan<br />';
                if ($qna> 0 )
                    echo $qna.' Quick Q &amp; A ToolKit<br />';
                if ($facts> 0 )
                    echo $facts.' Quick Facts ToolKit<br />';
                if ($calc> 0 )
                    echo $calc.' Calculators ToolKit<br />';
                if ($news> 0 )
                    echo $news.' Quarterly Newsletters ToolKit<br />';

                if($pro>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    echo $setupcomp.' Professional Plan ToolKit Setup No Charge<br />';

                if ($comp>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    echo $setupcomp.' Comprehensive Plan ToolKit Setup Charge<br />';

                if ($personal>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    echo $setuppersonal.' Personal Plan ToolKit Setup Charge<br />';

                if ($diy>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    echo $setupdiy.' DIY Plan ToolKit Setup Charge<br />';

                if ($host>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    echo $setuphost.' Hosting Only Plan ToolKit Setup Charge<br />';
                }
                

echo '<p>Order processed at ';
echo date('H:i, jS F');
echo '</p>';

?>
[/code]

Edited by toplay: To enclose code in forum code tags.

Share this post


Link to post
Share on other sites
$totalamount = $pro * PROPRICE
+ $comp * COMPPRICE
+ $personal * PERSONALPRICE
+ $diy * DIYPRICE
+ $host * HOSTPRICE
+ $qna * QNAPRICE
+ $facts * FACTSPRICE
+ $calc * CALCPRICE
+ $news * NEWSPRICE;
+ $setupcomp * SETUPCOMPPRICE;
+ $setuppersonal * SETUPPERSONALPRICE;
+ $setupdiy * SETUPDIYPRICE;
+ $setuphost * SETUPHOSTPRICE;


didn't look through the whole code, but I found some extra ;-thingies in here.

Try this:

$totalamount = $pro * PROPRICE
+ $comp * COMPPRICE
+ $personal * PERSONALPRICE
+ $diy * DIYPRICE
+ $host * HOSTPRICE
+ $qna * QNAPRICE
+ $facts * FACTSPRICE
+ $calc * CALCPRICE
+ $news * NEWSPRICE
+ $setupcomp * SETUPCOMPPRICE
+ $setuppersonal * SETUPPERSONALPRICE
+ $setupdiy * SETUPDIYPRICE
+ $setuphost * SETUPHOSTPRICE;

Share this post


Link to post
Share on other sites
Thanks, I had found those extra ";" but their removal didn't make any difference with respect to the outcome.

Share this post


Link to post
Share on other sites
hmm I see.

Ok, if you'd please clean up the script you posted and remove any unnecesary items I can look it through. Don't have too much time on my hand to figure all stuff out :)
or you could wait for someone else to help.

Share this post


Link to post
Share on other sites
See comments in code below:

[code]
<?php
// create short variable names
// Data returned from HTML forms are string by default. Make them integer.
$pro      = isset($_POST['pro']) ? intval($_POST['pro']) : 0;
$comp     = isset($_POST['comp']) ? intval($_POST['comp']) : 0;
$personal = isset($_POST['personal']) ? intval($_POST['personal']) : 0;
$diy      = isset($_POST['diy']) ? intval($_POST['diy']) : 0;
$host     = isset($_POST['host']) ? intval($_POST['host']) : 0;
$qna      = isset($_POST['qna']) ? intval($_POST['qna']) : 0;
$facts    = isset($_POST['facts']) ? intval($_POST['facts']) : 0;
$calc     = isset($_POST['calc']) ? intval($_POST['calc']) : 0;
$news     = isset($_POST['news']) ? intval($_POST['news']) : 0;

/** not used
$setupcomp     = isset($_POST['setupcomp']) ? intval($_POST['setupcomp']) : 0;
$setuppersonal = isset($_POST['setuppersonal']) ? intval($_POST['setuppersonal']) : 0;
$setuphost     = isset($_POST['setuphost']) ? intval($_POST['setuphost']) : 0;
**/

echo '<p>Your order is as follows: </p>';
$totalqty = (int) 0;
$totalqty = $pro + $comp + $personal + $diy + $host + $qna + $facts + $calc + $news; // not used: + $setupcomp + $setuppersonal + $setupdiy + $setuphost;
echo 'Items Ordered: '.$totalqty.'<br />';

$totalamount = (float) 0.00;

define('PROPRICE', 1.00);
define('COMPPRICE', 1.00);
define('PERSONALPRICE', 1.00);
define('DIYPRICE', 1.00);
define('HOSTPRICE', 1.00);
define('QNAPRICE', 1.00);
define('FACTSPRICE', 1.00);
define('CALCPRICE', 1.00);
define('NEWSPRICE', 1.00);
define('SETUPCOMPPRICE', 1.00);
define('SETUPPERSONALPRICE', 1.00);
define('SETUPDIYPRICE', 1.00);
define('SETUPHOSTPRICE', 1.00);

// Initialize
$setupcomp     = (int) 0;
$setuppersonal = (int) 0;
$setupdiy      = (int) 0;
$setuphost     = (int) 0;

// Set vars BEFORE calculating total amount
// What about pro?
if( $comp &&  ($qna>0||$facts>0||$calc>0||$news>0))
    $setupcomp = 1;

elseif( $personal &&  ($qna>0||$facts>0||$calc>0||$news>0))
        $setuppersonal = 1;

elseif( $diy &&  ($qna>0||$facts>0||$calc>0||$news>0))
        $setupdiy = 1;

elseif( $host &&  ($qna>0||$facts>0||$calc>0||$news>0))
        $setuphost = 1;

// Use parenthesis
$totalamount =    ($pro * PROPRICE)
                + ($comp * COMPPRICE)
                + ($personal * PERSONALPRICE)
                + ($diy * DIYPRICE)
                + ($host * HOSTPRICE)
                + ($qna * QNAPRICE)
                + ($facts * FACTSPRICE)
                + ($calc * CALCPRICE)
                + ($news * NEWSPRICE)
                + ($setupcomp * SETUPCOMPPRICE)
                + ($setuppersonal * SETUPPERSONALPRICE)
                + ($setupdiy * SETUPDIYPRICE)
                + ($setuphost * SETUPHOSTPRICE);

$totalamount = round($totalamount, 2); // Round to 2 decimal places

echo 'Subtotal: $', number_format($totalamount, 2), '<br />';

$taxrate = 1.15; // local salestax is 15%

$totalamount = round($totalamount * $taxrate, 2); // Round

echo 'Total including tax: $', number_format ($totalamount, 2), '<br />';

                if( $totalqty == 0 )
                {
                echo '<font color=red>';
                echo 'You did not order anything! <br />';
                echo '</font>';
                }

                if( $pro + $comp + $personal + $diy + $host> 1 )
                {
                echo '<font color=red>';
                echo 'You may only order one hosting plan! <br /> Please press your browsers back button and select the plan you want <br /> Your order cannot be processed<br />';
                echo '</font>';
                }

                if( $pro + $comp + $personal + $diy + $host == 0 )
                {
                echo '<font color=red>';
                echo 'You must order one hosting plan! <br /> Please press your browsers back button and make a selection <br />Your order cannot be processed<br />';
                echo '</font>';
                }

                else
                {
                if ($pro> 0 )
                    echo $pro.' Professional Plan<br />';
                if ($comp> 0 )
                    echo $comp.' Comprehensive Plan<br />';
                if ($personal> 0 )
                    echo $personal.' Personal Plan<br />';
                if ($diy> 0 )
                    echo $diy.' DIY Plan<br />';
                if ($host> 0 )
                    echo $host.' Hosting Only Plan<br />';
                if ($qna> 0 )
                    echo $qna.' Quick Q &amp; A ToolKit<br />';
                if ($facts> 0 )
                    echo $facts.' Quick Facts ToolKit<br />';
                if ($calc> 0 )
                    echo $calc.' Calculators ToolKit<br />';
                if ($news> 0 )
                    echo $news.' Quarterly Newsletters ToolKit<br />';

                if($pro>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    // Changed from $setupcomp to $pro. Check if that's what you want!
                    echo $pro.' Professional Plan ToolKit Setup No Charge<br />';

                if ($comp>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    echo $setupcomp.' Comprehensive Plan ToolKit Setup Charge<br />';

                if ($personal>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    echo $setuppersonal.' Personal Plan ToolKit Setup Charge<br />';

                if ($diy>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    echo $setupdiy.' DIY Plan ToolKit Setup Charge<br />';

                if ($host>0 && ($qna>0||$facts>0||$calc>0||$news>0))
                    echo $setuphost.' Hosting Only Plan ToolKit Setup Charge<br />';
                }


echo '<p>Order processed at ';
echo date('H:i, jS F');
echo '</p>';

?>
[/code]

Share this post


Link to post
Share on other sites

×

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.