Jump to content

Calculating PHP Form!


MjM8082

Recommended Posts

I have a form that I will post the code for. In my form I have a few things that need to be filled out.... Age, Gender, Coverage Amount, and Health Conditions.

 

The Health Conditions are 5 check boxes the user can select.

 

Now what I'm trying to do is make it so that when the user hits submit the Age and number of Health Conditions checked off will do this...

 

if # of Health Conditions <=2 and Age is <= 30 then = $0.90

 

if # of Health Conditions =>2 but <=5 and Age is <= 30 then = $1.20

 

Then after those are calculated I need these to apply to the code...

 

 

- Men are charged a 5% gender risk

- Students receive an 8% discount

 

 

Here is a example of what I'm trying to get this to do...

 

If you are a 23 year old male student who smokes but has no other risk factors your

premium amount per $10,000 would be $0.90 * 1.05 * 0.92 = $0.8694. If you wanted to take out a

$150,000 life insurance, your monthly premium would be $13.04 (15 * $0.8694).

 

 

 

I'm doing a life insurance form and these are some of the calculations that need to go into it. I'm not sure how I would code these. If someone could help me get started that would be great.

 

 

 

Here is my form code and the display page.

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>
    <title>Lab 4</title>
    
</head>


<body>
    <?php


?>



<form method="POST" action="lab4form.php">		

<label for="first_name">First Name:</label>
<input type="text" id="first_name" name="first_name" /><br />		
<label for="last_name">Last Name:</label>
<input type="text" id="last_name" name="last_name" /><br />	
<label for="coverage_amount">Coverage Amount:</label> 
<input type="text" id="coverage_amount" name="coverage_amount" /><br />	
<label for="gender">Gender:</label>
<br>
<input id="male" type="radio" value="Male" name="gender" />
	<label for="male">Male</label> 

<input id="female" type="radio" value="Female" name="gender" />
	<label for="female">Female</label> <br />
	<br>
<label for="Age">Age:</label>
<input type="text" id="age" name="age" /><br />	
<br>
<label for="health">Health Conditions</label> <br />

<input type="checkbox" name="health" value="Heart Disease" />
<label for="health">Heart Disease</label><br />

<input type="checkbox" name="health" value="Diabetes" />
<label for="health">Diabetes</label><br />

<input type="checkbox" name="health" value="High Blood Pressure" />
<label for="health">High Blood Pressure</label><br />

<input type="checkbox" name="health" value="Smoker" />
<label for="health">Smoker</label><br />

<input type="checkbox" name="health" value="Lung Disease" />
<label for="health">Lung disease</label><br />

<FORM METHOD=POST ACTION="lab4form.php">
<P>Employment Status<BR>
<SELECT NAME="employment">
<OPTION VALUE="Unemployed">Unemployed
<OPTION VALUE="Full-Time">Full-Time
<OPTION VALUE="Part-Time">Part-Time
<OPTION VALUE="Student">Student
</SELECT><br />
<br>
<label for="comments">Comments</label>
<input type="text" id="comments" name="comments"/><br />






<br>
<input type="submit" value="Add User" name="btn_add" />			
</form> 
</body>
</html>

 

 

 

 

Display Page

 

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

    

    <head>

        <title>Lab4</title>

        

    </head>

    <body>

    <div id="page">

        <div id="main">






        <div id="content">

            

            <h2>Life Insurance</h2>

            <table>

                <tr>

                    <th>Coverage Amount</th>

                    <th>Name</th>

                    <th>Gender</th>

				<th>Age</th>

				<th>Health Conditions</th>

				<th>Employment Status</th>

				<th>Comments</th>



                </tr>

			<?php

			$coverage_amount = $_POST['coverage_amount'];
			$age = $_POST['age'];
			$health = $_POST['health'];


			if $age = 



			?>










                                <tr>



                    <td><?php echo $_POST['coverage_amount'];?></td>

                    <td><?php echo $_POST['first_name'];?></td>

                    <td><?php echo $_POST['gender'];?></td>

				<td><?php echo $age?></td>

				<td class="right"><?php echo $_POST['health'];?></td>

				<td class="right"><?php echo $_POST['employment'];?></td>

				<td><?php echo $_POST['comments'];?></td>



                </tr>

                 

                            </table>

        </div>

        </div>

        <div id="footer"></div>

    </div>

    </body>

</html>

Link to comment
Share on other sites

might be looking for something like this then.

 

switch(true)

			{
			case($health <= 2 && $age <= 30):
				$premium_amount= 0.90*1.05*0.92;
				$final_premium_amount= 15*$premium_amount;
				break;

			case($health => 2 && $age <= 30):
				//formula here for this case
				break;

			}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.