elseif form variable help
Moderator: General Moderators
elseif form variable help
hello everybody....this probably really simple, but i need to pass a dependent variable (hidden) into my database.
What i want to say in this statement is depending on what the Race is, I need to associate the proper registartion $amount.
Should i have an elseif statement like thisin the middle of my form?
-------------------------------------------------------------
<tr><td>Race</td><td>
<select name="race">
<option value="">
<option value="5krun">5k Run
<option value="5kwalk">5k Walk
<option value="kids">Kids Races
</select>
</td></tr>
<?php
if( $race = 'kids' ) {
$amount = 3;
}elseif( $race = "5krun" ){
$amount = 15;
}elseof( $race = "5kwalk" ){
$amount = 15;
}
?>
--------------------------------------------------------------------
or How would i set an optional function for the VALUE?
<tr><td></td><td><input type="hidden" name="amount" value="
<?php
if( $race = 'kids' ) {
$amount = 3;
}elseif( $race = "5krun" ){
$amount = 15;
}elseof( $race = "5kwalk" ){
$amount = 15;
}
?>
"></td></tr>
????
Thanks,
-Michael
What i want to say in this statement is depending on what the Race is, I need to associate the proper registartion $amount.
Should i have an elseif statement like thisin the middle of my form?
-------------------------------------------------------------
<tr><td>Race</td><td>
<select name="race">
<option value="">
<option value="5krun">5k Run
<option value="5kwalk">5k Walk
<option value="kids">Kids Races
</select>
</td></tr>
<?php
if( $race = 'kids' ) {
$amount = 3;
}elseif( $race = "5krun" ){
$amount = 15;
}elseof( $race = "5kwalk" ){
$amount = 15;
}
?>
--------------------------------------------------------------------
or How would i set an optional function for the VALUE?
<tr><td></td><td><input type="hidden" name="amount" value="
<?php
if( $race = 'kids' ) {
$amount = 3;
}elseif( $race = "5krun" ){
$amount = 15;
}elseof( $race = "5kwalk" ){
$amount = 15;
}
?>
"></td></tr>
????
Thanks,
-Michael
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
You must use == instead of = though:
Code: Select all
<?php
if( $race == 'kids' ) {
$amount = 3;
}elseif( $race == "5krun" ){
$amount = 15;
}elseof( $race == "5kwalk" ){
$amount = 15;
}
?>
<input type="hidden" name="amount" value="<? echo $amount; ?>" />-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
Code: Select all
<?php
if( $race == 'kids' ) {
$amount = 3;
}elseif( $race == "5krun" ){
$amount = 15;
}elseif( $race == "5kwalk" ){ //misspelled elseif, you had elseof!!
$amount = 15;
}
?>I still can't get this to pass properly. This isn't placing the correct variable into $amount using this syntax.
here is what i have now, and it doesn't put anything in the amount varaible. There must be a slight syntax issue.
note: this is within the form tag.
--------------------------------------------------------------------------
<tr><td>Race</td><td>
<select name="race">
<option value="">
<option value="5krun">5k Run
<option value="5kwalk">5k Walk
<option value="kids">Kids Races
</select>
</td></tr>
<?php
if( $race == 'kids' ) {
$amount = 3;
}elseif( $race == "5krun" ){
$amount = 15;
}elseif( $race == "5kwalk" ){
$amount = 15;
}
?>
<tr><td></td><td><input type="hidden" name="amount" value="<?php echo $amount?>"><?php echo $amount?></td></tr>
-------------------------------------------------------------------------------------
thank you.
-mike
here is what i have now, and it doesn't put anything in the amount varaible. There must be a slight syntax issue.
note: this is within the form tag.
--------------------------------------------------------------------------
<tr><td>Race</td><td>
<select name="race">
<option value="">
<option value="5krun">5k Run
<option value="5kwalk">5k Walk
<option value="kids">Kids Races
</select>
</td></tr>
<?php
if( $race == 'kids' ) {
$amount = 3;
}elseif( $race == "5krun" ){
$amount = 15;
}elseif( $race == "5kwalk" ){
$amount = 15;
}
?>
<tr><td></td><td><input type="hidden" name="amount" value="<?php echo $amount?>"><?php echo $amount?></td></tr>
-------------------------------------------------------------------------------------
thank you.
-mike
and for testing purpose:
Code: Select all
<?php
if( $race == 'kids' ) {
$amount = 3;
}elseif( $race == "5krun" ){
$amount = 15;
}elseif( $race == "5kwalk" ){
$amount = 15;
}
echo "$amount";
// see if its passing the correct vaule.
?>
?>- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
To me, it makes more sense to do something like this:
Code: Select all
<form>
<table>
<tr>
<td>Races</td>
<td>
<select name="amount">
<option value="15">5k Run </option>
<option value="15">5k Walk </option>
<option value="3">Kids Races</option>
</select>
</td>
</tr>
</table>
</form>Are you gettting a value back for $race == 'kids'? Is $race set to anything? This code looks like you're relying on register globals, which is not good to get in the habit of doing. Beg pardon if I'm wrong, but I'm guessing on what you've shown.
How about this? I've eliminated a few tags for clarity. :
Hope this helps. For more on register globals, check http://www.php.net/register_globals
How about this? I've eliminated a few tags for clarity. :
Code: Select all
<html>
<head>
</head>
<body>
Race
<form action="<?php print $PHP_SELF; ?>" method="post">
<select name="race">
<option value=""></option>
<option value="5krun">5k Run</option>
<option value="5kwalk">5k Walk</option>
<option value="kids">Kids Races</option>
</select>
<input type="submit" value="tell me the amount!!!">
</form>
<?php
if($_POST['race'] == 'kids' ) {
$amount = 3;
}else if($_POST['race'] == "5krun" ){
$amount = 15;
}else if($_POST['race'] == "5kwalk" ){
$amount = 15;
}
print $amount;
?>
</body>
</html>ok, it's a syntax issue in the part the i noted, but i'll show you the whole code just to clarify:
-------------------------------------------------------
<?php
if ($submit) {
// process form
header("Location:http://www........com/....../verify.php?first_name=".$first_name."&last_name=".$last_name."&address1=".$address1."&city=".$city."&state=".$state."&zip=".$zip."&age=".$age."&sex=".$sex."&race=".$race."&amount=".$amount."&email=".$email."&night_phone_a=".$night_phone_a."&night_phone_b=".$night_phone_b."&night_phone_c=".$night_phone_c."&waiver=".$waiver."");
} else{
// display form
?>
<br><table align="center" bgcolor="#81B6ED" border="2" width="400">
<tr><td>
<form method="post" action="<?php echo $PHP_SELF?>" onSubmit="return Validator(this);">
<h3><center>Registration Form: </center></h3>
<table border="0" width="400">
<tr><td>First Name</td><td><input type="Text" name="first_name"></td></tr>
<tr><td>Last Name</td><td><input type="Text" name="last_name"></td></tr>
<tr><td>Address</td><td><input type="Text" name="address1"></td></tr>
<tr><td>City</td><td><input type="Text" name="city"></td></tr>
<tr><td>State</td><td>
<select name="state">
<option value>
<option value="AK" >AK
<option value="VI" >VI
</select>
</td></tr>
<tr><td>Zip Code</td><td><input type="Text" name="zip" size="5" maxlength="5"></td></tr>
<tr><td>Phone</td><td><input type='text' name="night_phone_a" size="3" maxlength="3"> <input type='text' name="night_phone_b" size="3" maxlength="3"> <input type='text' name="night_phone_c" size="4" maxlength="4"></td></tr>
<tr><td>Age on Race Day</td><td><input type="Text" name="age" size="3" maxlength="3"></td></tr>
<tr><td>Sex</td><td>
<select name="sex">
<option value="">
<option value="female">Female
<option value="male">Male
</select>
</td></tr>
<tr><td>Race</td><td>
<select name="race">
<option value="">
<option value="5krun">5k Run
<option value="5kwalk">5k Walk
<option value="kids">Kids Races
</select>
</td></tr>
<?php
if( $race == 'kids' ) {
$amount = 3;
}elseif( $race == "5krun" ){
$amount = 15;
}elseif( $race == "5kwalk" ){
$amount = 15;
}
?>
<tr><td></td><td><input type="hidden" name="amount" value="<?php echo $amount?>"><?php echo $amount?></td></tr>
<tr><td>Email</td><td><input type="Text" name="email"></td></tr>
</table>
<hr><table><tr><td>
<b>Waiver:</b>
</font>
<br>
<center><b>Check this button to agree <INPUT TYPE="checkbox" NAME="waiver" value="1">
</b></center></td></tr></table>
<hr><br>
<table align="center"><tr></td>
<center> <input type="Submit" name="submit" value="Submit"></center></td></tr></table>
</form>
<table align="center" bgcolor="gray"" border="0" width="250">
<tr><td><center><a href="http://www........com" target="rh">
<img src="/images/RH_1.gif" alt="" width="250" border="2"></a></center></td>
</tr></table>
<?php
} // end if
?>
--------------------------------------------------------
somehow the amount variable isn't getting set....it sets the race variable in the header, but amount is blank,
-mike
-------------------------------------------------------
<?php
if ($submit) {
// process form
header("Location:http://www........com/....../verify.php?first_name=".$first_name."&last_name=".$last_name."&address1=".$address1."&city=".$city."&state=".$state."&zip=".$zip."&age=".$age."&sex=".$sex."&race=".$race."&amount=".$amount."&email=".$email."&night_phone_a=".$night_phone_a."&night_phone_b=".$night_phone_b."&night_phone_c=".$night_phone_c."&waiver=".$waiver."");
} else{
// display form
?>
<br><table align="center" bgcolor="#81B6ED" border="2" width="400">
<tr><td>
<form method="post" action="<?php echo $PHP_SELF?>" onSubmit="return Validator(this);">
<h3><center>Registration Form: </center></h3>
<table border="0" width="400">
<tr><td>First Name</td><td><input type="Text" name="first_name"></td></tr>
<tr><td>Last Name</td><td><input type="Text" name="last_name"></td></tr>
<tr><td>Address</td><td><input type="Text" name="address1"></td></tr>
<tr><td>City</td><td><input type="Text" name="city"></td></tr>
<tr><td>State</td><td>
<select name="state">
<option value>
<option value="AK" >AK
<option value="VI" >VI
</select>
</td></tr>
<tr><td>Zip Code</td><td><input type="Text" name="zip" size="5" maxlength="5"></td></tr>
<tr><td>Phone</td><td><input type='text' name="night_phone_a" size="3" maxlength="3"> <input type='text' name="night_phone_b" size="3" maxlength="3"> <input type='text' name="night_phone_c" size="4" maxlength="4"></td></tr>
<tr><td>Age on Race Day</td><td><input type="Text" name="age" size="3" maxlength="3"></td></tr>
<tr><td>Sex</td><td>
<select name="sex">
<option value="">
<option value="female">Female
<option value="male">Male
</select>
</td></tr>
<tr><td>Race</td><td>
<select name="race">
<option value="">
<option value="5krun">5k Run
<option value="5kwalk">5k Walk
<option value="kids">Kids Races
</select>
</td></tr>
<?php
if( $race == 'kids' ) {
$amount = 3;
}elseif( $race == "5krun" ){
$amount = 15;
}elseif( $race == "5kwalk" ){
$amount = 15;
}
?>
<tr><td></td><td><input type="hidden" name="amount" value="<?php echo $amount?>"><?php echo $amount?></td></tr>
<tr><td>Email</td><td><input type="Text" name="email"></td></tr>
</table>
<hr><table><tr><td>
<b>Waiver:</b>
</font>
<br>
<center><b>Check this button to agree <INPUT TYPE="checkbox" NAME="waiver" value="1">
</b></center></td></tr></table>
<hr><br>
<table align="center"><tr></td>
<center> <input type="Submit" name="submit" value="Submit"></center></td></tr></table>
</form>
<table align="center" bgcolor="gray"" border="0" width="250">
<tr><td><center><a href="http://www........com" target="rh">
<img src="/images/RH_1.gif" alt="" width="250" border="2"></a></center></td>
</tr></table>
<?php
} // end if
?>
--------------------------------------------------------
somehow the amount variable isn't getting set....it sets the race variable in the header, but amount is blank,
-mike
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
the problem now is that i use this to process the form:
<form method="post" action="verify.php" onSubmit="return Validator(this);">
My Verify.php page, displays all the variables in another final form which the customer then submits into the database and on to paypal.
What is happening now is the this form is going right to paypal and bypassing the verify.php page.
any ideas?
-mike
<form method="post" action="verify.php" onSubmit="return Validator(this);">
My Verify.php page, displays all the variables in another final form which the customer then submits into the database and on to paypal.
What is happening now is the this form is going right to paypal and bypassing the verify.php page.
any ideas?
-mike