thanks a lot for helping me.. i tried to upgrade to 5.5 in my cpanel but i get internal server error so i reverted back to 5.2
<select name="state" >
<?php
$states = array(
'CA' => 'California',
'FL' => 'Florida',
'NY' => 'New York',
);
?>
<option value="">---</option>
<?php foreach ($states as $abbr => $name): ?>
<option value="<?= $abbr; ?>"><?= $name; ?></option>
<?php endforeach; ?>
</select>
PHP IF code
Moderator: General Moderators
Re: PHP IF code
i used the code for 5.2 and it still doesn't work.
Re: PHP IF code
there isn't a way i can just set a variable on my process page
$fullstatename = florida
$abbreviation = FL
thats all i want to come out of it
$fullstatename = florida
$abbreviation = FL
thats all i want to come out of it
Re: PHP IF code
That's not really giving me much to work with. Is error reporting turned on? What error(s) are you seeing? What's happening? The more specific you can be, the better.donny wrote:it still doesn't work.
Re: PHP IF code
how do i turn on error reporting? in my cpanel i have it turned on if thats how it is turned on.
the form option field doesn't list any states
the form option field doesn't list any states
Code: Select all
<select name="state" >
<?php
$states = array(
'CA' => 'California',
'FL' => 'Florida',
'NY' => 'New York',
);
?>
<option value="">---</option>
<?php foreach ($states as $abbr => $name): ?>
<option value="<?= $abbr; ?>"><?= $name; ?></option>
<?php endforeach; ?>
</select>
Re: PHP IF code
basically i just want to have my form option select a state... and on my next page i want it to be in 2 variables $fullstatename $stateabbreviation
thats all
thats all
Re: PHP IF code
Code: Select all
error_reporting(-1);Re: PHP IF code
my site isn't live yet.. there isnt a way i can set the abbreviation variable on the processing page like if $state = California then $abbreviation = CA
something along those lines?
something along those lines?
Re: PHP IF code
That's exactly what we've been trying to do. Using an array seems both the simplest and most easily extensible. Sure, you could set up a bunch of conditionals
But that's not terribly efficient and it's ignoring the larger problem of why iterating over an array isn't working.
Code: Select all
if ($_POST['state'] == 'California') {
$state_abbr = 'CA';
} else if ($_POST['state'] == 'New York') {
$state_abbr = 'NY';
}
// etcRe: PHP IF code
it works for me.
thanks a lot for helping
thanks a lot for helping
Re: PHP IF code
Code: Select all
if ($_POST['state'] == 'California') {
$state_abbr = 'CA';
} else if ($_POST['state'] == 'New York') {
$state_abbr = 'NY';
}
// etc
also is it possible to run another version of this script with different fields on the same process page?
Re: PHP IF code
Just keep adding else if statements. Like I mentioned above, though, that's really solving the wrong problem.