/    Sign up×
Community /Pin to ProfileBookmark

Newbie needs HELP with form calc

Hello all!

I’m attempting to create a form with three drop selects (containing numerous options) which will return a specific rate and verify the options selected (e.g. “A yearly [1] [2] membership costs [3].”).

Although I’ve customized PHP/MySQL apps in the past (forums, shopping carts, etc.), I don’t yet know enough to script it “correctly.”

I’ve setup the MySQL database and have a PHP script which works when the first option is selected with the other two defined in the script. Obviously, this is not what I’m aiming for. I know a tight script can be written to do this.

If I supply more details, can any of you crack PHPers lend a hand? Greatly appreciated!

J ?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 12.2004 — Afraid I'm not entirely clear as to what the question is. From the example, it seems you are looking to take options [1] and [2] from the user, and then calculate the cost [3] and display all 3 items back to the user for confirmation. But then you said that all 3 items would be selected/input by the user, so I'm confused. ?
Copy linkTweet thisAlerts:
@JohnFordauthorNov 12.2004 — Sorry! That's right. Forgot to include a third option, but it would not be included in the output confirmation string.

The form:

Category: [Options = Family, Couple, Adult, et al]

Type: [Options = City, Center]

Income Range [Options = $55,000-$64,900, $50,000-$54,900, et al]

Output = category, type, income range
Copy linkTweet thisAlerts:
@NogDogNov 12.2004 — Well, here's a simple script to show you one way of inputting and outputting the data:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
<title>Sample PHP Script</title>
<style type="text/css">
</style>
</head>
<body>
<?php
# common data:
$category = array("Family", "Couple", "Adult");
$type = array("City", "Center");
$incomeRange = array("$55,000-$64,900", "$50,000-$54,900");
# see if any POST data received:
if(isset($_POST['category']))
# process input from form
{
echo "<h1>Results</h1>n";
echo "You selected <b>{$category[$_POST['category']]}</b>,";
echo "<b>{$type[$_POST['type']]}</b>,";
echo "and <b>{$incomeRange[$_POST['incomeRange']]}</b>.n";
}
else
# display input form
{
echo "<h1>Input Form</h1>n";
echo "<form action='{$_SERVER['PHP_SELF']}' method=post>n";
# category select:
echo "<p>Category: <select name='category'>n";
foreach($category as $key => $value)
{
echo "<option value='$key'>$value</option>n";
}
echo "</select></p>n";
# type select:
echo "<p>Type: <select name='type'>n";
foreach($type as $key => $value)
{
echo "<option value='$key'>$value</option>n";
}
echo "</select></p>n";
# income range select:
echo "<p>Income Range: <select name='incomeRange'>n";
foreach($incomeRange as $key => $value)
{
echo "<option value='$key'>$value</option>n";
}
echo "</select></p>n";
echo "<p><input type=submit value='Submit Form'></p>n";
echo "</form>n";
}
?>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@JohnFordauthorNov 12.2004 — Thanks NogDog!

Works great with the three option arrays. Now I'll need to return data I've placed in my database - namely the rates which correspond to the chosen options. What's the best way to connect this data to the three data arrays?
Copy linkTweet thisAlerts:
@NogDogNov 12.2004 — http://www.php.net/manual/en/ref.mysql.php is a good place to start.

Or, you could send me the entire requirements, then we could negotiate a contract for me to program it. ?
Copy linkTweet thisAlerts:
@JohnFordauthorNov 12.2004 — May just do that if I don't get up to speed quickly enough. Right now, I know just enough to get in trouble. ?

Thanks!
×

Success!

Help @JohnFord spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...