Jump to content

Beginner Needs Help


chatyak

Recommended Posts

Hello,

 

For all purposes, I am a complete beginner. I just know the basics of passing form data through to an email, and displaying the text of a variable on the next page via ECHO, POST, etc..

 

My situation is that I do not know what sort of code to use to accomplish the job of what I want done. I have created a form to be used for displaying insurance information. This form allows users to select the following:

 

To Get Started:

State You Live In:

 

Car Information:

Model Year:

Original Listing Price:

Your Car Currently Is:

 

Your Information:

Do You Rent Or Own?

Are You Married?

Do You Have Children Under 18 Years Of Age?

Gross Annual Household Salary

Do You Have Health Insurance?

How Much Are You Worth In Total Assets (Savings, Equity, Stocks, 401K, Car, Home, etc...)

 

------------------------

 

Next to each question, I have a box from which they can select their options (standard html form code). The form has an action and the method is post. Some code is displayed below.. Now so far I am able to display the text of whatever item they selected, by using Echo $_Post etc and the answer page... Here is my problem...

 

 

I want to display to the user, "recommended insurance limits" based on the data they select from the drop down boxes. So... If a user lives in Alabama, and has an income of $150K+, I want to display a different answer than someone who only earns $30K and lives in Alabama, and the list goes on, (range of options for each question).

 

I have no idea what sort of code to use to display the appropriate answer. I thought I could use the "if, elseif, else" statement, and simply do hundreds of variations on it for each state, but surely there is a more refined and less bloated code for doing such a thing?

 

I would need to display a different answer for the user, for each separate option they choose.

 

Example) Alabama, Model Year of 1995, Salary of $50K would be DIFFERENT then Alabama, Model Year of 2000, Salary of $50K, etc...

 

Thank you for your time.

 

 

Here is my php code.

 

<?php
$state = $_POST["state"];
$modelyear = $_POST["modelyear"];
$carprice = $_POST["carprice"];
$carownership = $_POST["carownership"];
$homeownership = $_POST["homeownership"];
$marriage = $_POST["marriage"];
$childrenunder18 = $_POST["childrenunder18"];
$salary = $_POST["salary"];
$healthinsurance = $_POST["healthinsurance"];
$assets = $_POST["assets"];
?>
<?php
if ($state=="Alabama")
  {
  echo "Alabama requires the following minimum insurance limits:<br />
$25,000 - Liability Per Person<br />
$50,000 - Liability For Total Persons<br />
$25,000 - Property Damage Total";
  }
elseif ($state=="Alaska")
{
echo "Alaska requires etc...";
}
else
{
echo "You did not select a state.";
}
  ?>

 

 

 

Link to comment
Share on other sites

Hello,

 

I have figured some more out and am quite happy with the results. I have a question that may solve this problem.

 

What code would I use to specify a certain range of answers? For example, I have the following code:

 

<?php
if ($answer=="Alabama, Before 1995, Under $20K, Leased, Rent, Yes, Yes, Under $30K, No, $0 - $5K")
echo "You should consider getting $100000K in coverage";
elseif ($answer=="Alabama, Before 1995, Under $20K, Leased, Rent, Yes, No, Under $30K, No, $0 - $5K")
echo "You should consider getting $2000000 in coverage";
else
echo "Nothing here";
?>

 

 

But what if I want to do this? Bold highlighted is the change.

 

<?php

if ($answer=="Alabama, From Before 1995 To 2005 (a range of potential selections that user may have chosen), Under $20K, Leased, Rent, Yes, Yes, Under $30K, No, $0 - $5K")

echo "You should consider getting $100000K in coverage";

elseif ($answer=="Alabama, Before 1995, Under $20K, Leased, Rent, Yes, No, Under $30K, No, $0 - $5K")

echo "You should consider getting $2000000 in coverage";

else

echo "Nothing here";

?>

 

 

What exactly is the code to specify a range of options?

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.