Jump to content

Form results: using math in echo


ringartdesign

Recommended Posts

I've got a website I'm putting together for my small insurance agency. Basically I want to give the viewer a quote based on their age and sex. I'd like to be able to add their spouses age and sex to the equation as well as up to 3 children (anything over 4+ children are free). The php code below that works for the age range but does not give a different quote based on the sex. My question is:

 

Can you advise on how to edit this PHP code below to factor in the sex of the person?

 

PHP CODE

<?php

//page display after form submission

echo "<p><CENTER>Thank you, <b>$_POST[name]</b>, for requesting a quote.<br>

Your are eligable for heatlh insurance rates as low as:</p>";

if (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] ="male"))

$quote=31.44;

elseif (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] ="female"))

$quote=44.65;

elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] ="male"))

$quote=35.91;

elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] ="female"))

$quote=35.91;

elseif (($_POST['age'] >= 31) && ($_POST['age'] <= 35) && ($_POST['sex'] ="male"))

$quote=40.78;

elseif (($_POST['age'] >= 31) && ($_POST['age'] <= 35) && ($_POST['sex'] ="female"))

$quote=62.11;

elseif (($_POST['age'] >= 36) && ($_POST['age'] <= 40) && ($_POST['sex'] ="male"))

$quote=51.33;

elseif (($_POST['age'] >= 36) && ($_POST['age'] <= 40) && ($_POST['sex'] ="female"))

$quote=76.72;

elseif (($_POST['age'] >= 41) && ($_POST['age'] <= 45) && ($_POST['sex'] ="male"))

$quote=65.95;

elseif (($_POST['age'] >= 41) && ($_POST['age'] <= 45) && ($_POST['sex'] ="female"))

$quote=92.55;

elseif (($_POST['age'] >= 46) && ($_POST['age'] <= 50) && ($_POST['sex'] ="male"))

$quote=87.87;

elseif (($_POST['age'] >= 46) && ($_POST['age'] <= 50) && ($_POST['sex'] ="female"))

$quote=108.38;

elseif (($_POST['age'] >= 51) && ($_POST['age'] <= 60) && ($_POST['sex'] ="male"))

$quote=117.50;

elseif (($_POST['age'] >= 51) && ($_POST['age'] <= 60) && ($_POST['sex'] ="female"))

$quote=126.65;

elseif (($_POST['age'] >= 61) && ($_POST['age'] <= 64) && ($_POST['sex'] ="male"))

$quote=184.07;

elseif (($_POST['age'] >= 61) && ($_POST['age'] <= 64) && ($_POST['sex'] ="female"))

$quote=168.87;

//add children

$quote+=($_POST['children']*30.04);

echo "$".$quote."/month</p>

<p>CALL NOW: 1-877-123-4567<br>

TO START YOUR HEALTH INSURANCE COVERAGE!</p>";

 

//start building the mail string

$msg = "Name:    $_POST[name]\n";

$msg .= "Age:  $_POST[age]\n";

$msg .= "Sex:  $_POST[sex]\n";

$msg .= "Children:  $_POST[children]\n";

$msg .= "E-Mail:  $_POST\n";

$msg .= "Message: $_POST[message]\n";

 

//set up the mail to company

$recipient = "[email protected]";

$subject = "Health Insurance Quote";

$mailheaders = "From: 2 Step Health <[email protected]> \n";

 

//send the mail to company

mail($recipient, $subject, $msg, $mailheaders);

?>

Link to comment
https://forums.phpfreaks.com/topic/125395-form-results-using-math-in-echo/
Share on other sites

That worked! Thank You! 2 more questions...

 

How could I add the spouse's quote to it? All values would be exactly the same except "age" would be "spouse_age" and "sex" would be "spouse_sex"?

 

Also, I added children by doing this:

$quote+=($_POST['children']*30.04);

 

But I need it to stop adding 30.04 for 4+ children. (ie - 1 child = 30.04, 2 children = 60.08, 3 children = 90.12, {more than 3 remains the same} 4 children = 90.12)

 

Thanks!!!

Archived

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

×
×
  • Create New...

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.