help with new variables

Hello:

I have a working .php script that I need two more variables added to. The first variable is called “Leafguard” and if someone enters “N” then $0 gets added to the price. If someone enters “Y” then the calculation is (length of gutter x width of gutter = ###) then (### x $4.25 = XXX) and then add XXX to the total cost.

The second variable is Drainguard and the calculation is if “n” is entered $0 gets added to the total cost and if “Y” is entered (# of downpipes x $40 = XXX) add XXX to the total cost.

I hope this makes sense. It should once the original script is looked at.

Any help would be greatly appreciated!

Dianna

[php]

<?php $lengthNum = $_POST['lengthNum']; $widthNum = $_POST['widthNum']; $storiesNum = $_POST['storiesNum']; $cornersNum = $_POST['cornersNum']; $capsNum = $_POST['capsNum']; $downpipesNum = $_POST['downpipesNum']; $cornersTtl = $cornersNum * 3; $downpipesTtl = ($downpipesNum * 10) * $storiesNum + ($downpipesNum * 2); $lengthTtl = $lengthNum * 2; $widthTtl = $widthNum * 2; $ttlNum = ($widthTtl + $lengthTtl + $downpipesTtl + $capsNum + $cornersTtl + $downpipesNum) * 1.1 * 4.75; $ttlCost = number_format($ttlNum,2,".",","); if(!is_numeric($lengthNum) || !is_numeric($widthNum) || !is_numeric($storiesNum) || !is_numeric($cornersNum) || !is_numeric($capsNum) || !is_numeric($downpipesNum)) { $error = 1; $error_html .= "Only numbers are permitted.

\n"; } if($lengthNum == "") { $error = 1; $error_html .= "Please provide the Length of your house in feet.

\n"; } if($widthNum == "") { $error = 1; $error_html .= "Please provide the Width of your house in feet.

\n"; } if($storiesNum == "") { $error = 1; $error_html .= "Please provide the number of stories of your house.

\n"; } if($cornersNum == "") { $error = 1; $error_html .= "Please tell us how many Corners your gutter has.

\n"; } if($capsNum == "") { $error = 1; $error_html .= "Please tell us how many Endcaps your gutter has.

\n"; } if($downpipesNum == "") { $error = 1; $error_html .= "Please tell us how may Downpipes your gutter has.

\n"; } if($error == "1") { echo ' Acme Gutterworks - Auto Quote System '; include('header.inc'); echo '

 

'; echo '


For your submission to be effective it is important that you complete all of the required fields. Your submission was rejected for the following reasons:

' . $error_html . '

Please go back and try again.

'; include('footer.inc'); } else { echo ' Acme Gutterworks - Auto Quote System '; include('header.inc'); echo '

Acme Gutterworks - Auto Quote System

'; echo '

If you want to be contacted about your project please fill in this form and send. Fields marked with an * are Required

Name*

E-Mail*

Phone

House
Length in feet: ' . $lengthNum . '
Width in feet: ' . $widthNum . '
Stories: ' . $storiesNum . '
 
Gutter System
Corners: ' . $cornersNum . '
Endcaps: ' . $capsNum . '
Downpipes: ' . $downpipesNum . '

Cost:   $ ' . $ttlCost . '

'; echo '

Actual cost will likely come in a little lower when your Acme Gutterworks representative takes their own precise measurements.

'; echo '

 

'; echo '

 

'; echo '

 

'; echo '

 

'; echo '

 

'; echo '

 

'; echo '

 

'; echo '

 

'; echo '

 

'; echo '

 

'; include('footer.inc'); } ?>

[/php]

Well, not sure what help you wanted, but, that is simple code. This would be just a sample, you will have to tune it up to fit your form which we did not see. (Not needed really!) But, you may have to alter this sample a bit… Anways, you can just add something like this just before:

$ttlCost = number_format($ttlNum,2,".",",");

[php]

if ($Leafguard==“Y”){
// $ttlCost is TOTAL COST, $gutterLength is length of gutter, $gutterWidth is width of gutter!
$ttlCost = $ttlCost + $gutterLength * $gutterWidth * 4.25;
}

if ($Drainguard==“Y”){
// $downPipesCount is the number of downpipes!
$ttlCost = $ttlCost + $downPipesCount * 40;
}

[/php]

You really do not need the brackets and the $ttlCost=$ttlCost+ ccan be shortend to $ttlCost+…
I left it this way so you can see the logic of it. The shortened version is below, but, is harder to read for some people…

[php]

if ($Leafguard==“Y”) $ttlCost+ $gutterLength * $gutterWidth * 4.25;

if ($Drainguard==“Y”) $ttlCost+ $downPipesCount * 40;

[/php]

At least, I think that is what you are asking for… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service