Page 1 of 2

elseif form variable help

Posted: Fri Mar 12, 2004 5:22 pm
by speedamp
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

Posted: Fri Mar 12, 2004 5:23 pm
by andre_c
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; ?>" />

Posted: Fri Mar 12, 2004 5:33 pm
by Illusionist

Code: Select all

<?php

if( $race == 'kids' ) {
$amount = 3;
}elseif( $race == "5krun" ){
$amount = 15;
}elseif( $race == "5kwalk" ){ //misspelled elseif, you had elseof!! 
$amount = 15;
}
?>

Posted: Fri Mar 12, 2004 6:30 pm
by speedamp
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

Posted: Fri Mar 12, 2004 6:33 pm
by andre_c
Are you putting a <form> tag around it? Can you show all of the code for that page?

Posted: Fri Mar 12, 2004 6:36 pm
by tim
i dont understand:

value="<?php echo $amount?>"><?php echo $amount?>

Posted: Fri Mar 12, 2004 6:38 pm
by tim
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.
?> 

?>

Posted: Fri Mar 12, 2004 6:40 pm
by andre_c
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>

Posted: Fri Mar 12, 2004 7:24 pm
by angrytuna
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. :

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>
Hope this helps. For more on register globals, check http://www.php.net/register_globals

Posted: Fri Mar 12, 2004 7:45 pm
by speedamp
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">&nbsp; <input type='text' name="night_phone_b" size="3" maxlength="3">&nbsp; <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

Posted: Fri Mar 12, 2004 7:49 pm
by Illusionist
wow!!!! LOL, you probably do nto want to do taht at all(that long URL). I highly suggest changing your form action to verify.php, and pass teh variables by post, sot he end-user doesn't have to see them and deal with them, and avoid nasty long URL like you got there!

Posted: Fri Mar 12, 2004 7:51 pm
by andre_c
It's not being set because the information has not gone to the webserver to be parsed. Instead of doing if ($submit) and all that do:
<form action='verify.php'>
and send the information straight to the handler page.

Posted: Fri Mar 12, 2004 7:51 pm
by Illusionist
yeah, i agree with andre_c!! hehe

Posted: Fri Mar 12, 2004 10:04 pm
by speedamp
ok, i'll try that but everything on this works EXCEPT the $amount variable is not getting passed.

why is that? what is wrong with the $amount syntax.

-mike

Posted: Fri Mar 12, 2004 10:25 pm
by speedamp
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