Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

order entry results missing one item - cannot figure it out 1

Status
Not open for further replies.

drtom

Technical User
Feb 26, 2004
369
0
0
CA
I know I'm going to feel relatively dumb when someone points out my error so, thanks in advance.

I am trying to create a simple order entry process. My order entry form is at
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 (as outlined on the form) and add the tax.

Thus far the php code returns the correct items sold and calculates the order total including tax for the plans and the toolkits and even indicates that the order includes the correct setup charge but the process will not add the appropriate amount for the setup charge to the order.

$totalamount includes all of the variables but I just cannot see what I'm missing.

Any insight will be greatfully appreciated. Once 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'];
$setupdiy = $_POST['setupdiy'];
$setuphost = $_POST['setuphost'];
$cust_name = $_POST['cust_name'];


echo '<p>Thank you for your order '.$cust_name.' <br />
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;
				


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

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

$tax = $totalamount * $taxrate;

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

$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>';
				}
				
				if( $comp &&  ($qna>0||$facts>0||$calc>0||$news>0))
					$setupcomp = 1;

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

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

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

				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>';

?>
 
you're not really telling us what each variable means. we *might* be able to guess but this perhaps is not appropriate.

one thought though - towards the bottom of your script, you are just echoing out the variables received from the form. We don't know what the form says so this may be fine. but elsewhere you are multiplying form values by definitions.

so should
Code:
  echo $setuphost.' Hosting Only Plan ToolKit Setup Charge<br />';
be:(?)
Code:
  echo ($setuphost * SETUPHOSTPRICE).' Hosting Only Plan ToolKit Setup Charge<br />';

or if the above is only supposed to be quantitative i cannot see anywhere in the code where this calculation is done separately for you to be able to show it. i accept that it is done properly done inside the totalamount calculation. if this is where your issue is you should start by dumping all your post variables on the way in and being certain that the expected values are being received.
 
Thanks Justin for your reply. You have to bear with me this is still very new to me. As I'm sure you're aware, it’s a big text book

you're not really telling us what each variable means. we *might* be able to guess but this perhaps is not appropriate.

Do you mean that, for clarity I should add a comment for each one? For example:
Code:
$pro = $_POST['pro']; // Professional Plan
$comp = $_POST['comp']; // Comprehensive Plan
$personal = $_POST['personal']; // Personal Plan
We don't know what the form says
The form is at
I want to add the setup charge to the order (i.e. $setuphost) when $host is selected along with any 1, 2, 3, or 4 toolkit options (i.e. $facts) along with the chosen plan and toolkits.
Right now it is calculating the cost of the plan ($host) plus the cost of the toolkits ($facts etc.) adding the tax
and returning the total amount and what the customer ordered. It will not add the cost of the setup charge ($setuphost) to the order in spite of it returning the line "Hosting Only Plan ToolKit Setup Charge".
I am under the impression that $setuphost is being (should be) dealt with in the same fashion as the other $whatevers.
i cannot see anywhere in the code where this calculation is done separately for you to be able to show it.
Are they all not being done in the same fashion here?
Code:
$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;
Thanks
 
DrTom

i've had a look at the form and the script and recreated them on my servers.

the form delivers the following variables into $_POST (excuse the formatting)
Code:
    [pro],
    [comp] => 
    [personal] => 
    [diy] => 
    [host] => 
    [qna] => 1
    [facts] => 
    [calc] => 
    [news] => 
    [cust_name]

but you are trying to make use of the following variables in the totalamount calculation:
Code:
$setupcomp * SETUPCOMPPRICE            
        + $setuppersonal * SETUPPERSONALPRICE        
        + $setupdiy * SETUPDIYPRICE            
        + $setuphost * SETUPHOSTPRICE;

these are null and so are treated as zeros.

if you turn error reporting on
Code:
error_reporting(E_ALL);
as i recommend you do for all debugging you would get the following notices:

Code:
Notice:  Undefined index:  setupcomp in c:\Inetpub\[URL unfurl="true"]wwwroot\tmogolf\tektips\processorder.php[/URL] on line 17

Notice:  Undefined index:  setuppersonal in c:\Inetpub\[URL unfurl="true"]wwwroot\tmogolf\tektips\processorder.php[/URL] on line 18

Notice:  Undefined index:  setupdiy in c:\Inetpub\[URL unfurl="true"]wwwroot\tmogolf\tektips\processorder.php[/URL] on line 19

Notice:  Undefined index:  setuphost in c:\Inetpub\[URL unfurl="true"]wwwroot\tmogolf\tektips\processorder.php[/URL] on line 20

which i am sure would have put you on the right track.

I also think that your approach to validation is worthy but slightly short of the mark. there are easier ways to do this, not least by restructuring your form.

i have taken the (large) liberty of fixing up your code for both the form and the script - to show you how to simplify your validation routines and also make your scripts more secure.

i have posted them on my site at as they would be rather large to post on this forum.

hth
justin
 
YOU are truly a STAR !!

Looking through the content it currently goes beyond my early skill level but I am going to enjoy learning about each unfamiliar part.

I didn't intend for you to write it but thanks.

Couple of ?'s

1 - Why did you make the form a php file vs. html?

2 - Can you recommend a good instructional book / text to work from? I currently have PHP & MySQL Web Development by Welling & Thomson. I think I can see the value in this one but for someone who is absolutely starting is there a recommendation?

Doc
 
Justin:
I just noticed... what's tmo[COLOR=#ff000]golf[/color]?
 
as posted above: the error in your code was that you were not sending variables from your form to your script. hopefully that pointer enabled you to fix the code in the way you had written it.

My aim in providing the extra code was to show you about validation and how the design of your form can make your subsequent script validation easier.

some of the code constructs that i used are not basic (i accept that) but they're not too bad!

hopefully i put comments on the sections that i thought would need explanation. if you want clarification on any particular bit just post back or email me (my email address is occluded in my profile)

your questions:

1 - Why did you make the form a php file vs. html?

absolutely no reason at all. just force of habit. the vast majority of my applications work on the dispatch method (i.e. one central page does absolutely everything, pulling in other modules as and when needed). by putting all files as php it means that the source code is never revealed. there would be no change in output at all if it were an html file.

2. a good book?
i started with the nutshell book on php (Rasmus Lerdorf i think wrote it) but put it down after an hour or so. to be honest i have not spent long with books but instead used google and hotscripts to examine other people's code and learn from their ways of doing things. i learned by setting myself tasks and building from there. i also learn new things pretty much every day on this forum.

have fun
justin
 
i also learn new things pretty much every day on this forum.
Boy... that's the truth

And the Golf connection?
 
I used to be head of legal (general counsel) for T-Mobile International (owns T-Mobile in the US amongst other things).

My very first php project was to build a golf scorer that a bunch of us could use on mobile phones for some afternoon out of the office. the domain name of tmogolf (T-Mobile Organisation Golf) was the best i could come up with at the time! (TMO was the acronym we used internally - i didn't make it up!).

i don't really use it any more! the web space has a whole bunch of different domains attributed to various directories - again i have not got around to assigning a nice one to the tektips bit!


 
Oh, I thought we might have something in common.
My background is 35 years in the golf industry of which I have retired out of.
Computers are far more fun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top