Slight Selection Problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bumple
Forum Commoner
Posts: 34
Joined: Thu Jan 08, 2004 4:38 am

Slight Selection Problem!

Post by bumple »

Hey all,

I have a website where users come, sign up, and manage a few small portfolios (not stocks). As of now, users can successfully view all their portfolios, but I am making a "My Account" page, where users can change the information they signed up with (name, state, country, zip, password, etc.). This page works perfectly fine, it updates everything, it's just that when users come I have three slight problems:

1) When users sign up, they choose a state. Let's say I signed up with Alabama...it has "AL" stored in my database. Now, when users go to the "My Account" page, how do I make the dropdown menu automatically scroll down and have preselected the "AL" selection (Alabama)?

2) Same problem happens with Country, if I figure out how to fix the state, this will be easy to fix

3) In the "My Account" page, I also allow users to change their password. However, when they come to the page, the password box is blank, and they are FORCED to type in a new password to update their account information. How do I make it fetch the password from the database, and have it in the textbox? I use MD5 encryption, does this mean I can't decrypt it and have it appear (as a password) in the box? With all my other textfields, this worked, but with the password, when I type:
[syntax=php]<input type="password" name="passwd" value="<?php echo $password;?>" maxlength="10">[/syntax]
it doesn't output the password in the box, it is just a full textbox and probably, when decrypted, says exactly what was in the initial value box (<?php echo $password;?>). How can I get around this?


Thanks a lot guys! Any help would be appreciated!
-BUMPle.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

3. Give them an option (checkbox?) whether to change their password or not.

Changing of a password is a big deal, i'd actually suggest a whole page for that (ie. account.php?page=changepass).

for the scrolling, theres a default value or something like that, check around under input tag attributes or something :P
bumple
Forum Commoner
Posts: 34
Joined: Thu Jan 08, 2004 4:38 am

Post by bumple »

Thanks a lot, I'll work on that...
as for the first two...


It looks like this, but a bit abridged:
[syntax=php]<select name="state" size="1">
<option value="ZZ"></option>
<option value="null">-- UNITED STATES --</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
</select>[/syntax]

The variable name is $state, so in $state, there is stored "AL". How exactly would I tell this to scroll down to "AL"?

Thanks a lot!

-BUMPle.
bumple
Forum Commoner
Posts: 34
Joined: Thu Jan 08, 2004 4:38 am

Post by bumple »

BUMPity!

-BUMPle.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Wow, this is going to take some work. In HTML, to show the selected dropdown, you have to add selected="selected" to the correct <option>. That means you may have to add an IF statement to every single one of the option menus unless someone can come up with a better idea. The best woul probably be to put all the countries in an array, check which country they have, add the selected="selected" to that array value and then loop through the array.

Heres how to do it the first way:

Code: Select all

<?php
$state = "INFO FROM DATABASE";  //eg: $state = "AL";
?>
<select name="state" size="1"> 
<option value="ZZ"></option> 
<option value="null">-- UNITED STATES --</option> 
<option value="AL"<?php if($state == "AL") {echo " selected="selected"";} ?>>Alabama</option> 
<option value="AK"<?php if($state == "AK") {echo " selected="selected"";} ?>>Alaska</option> 
<option value="AZ"<?php if($state == "AZ") {echo " selected="selected"";} ?>>Arizona</option> 
</select>
As you can see, that would just suck.

So my idea would be this:

Code: Select all

<?php
$statesArray = array(
"AL" => "Alabama", 
"AK" => "Alaska", 
"AZ" => "Arizona"
) //etc, etc
$state = "INFO FROM DATABASE"; //eg: $state = "AL";
?>
<select name="state" size="1"> 
<option value="ZZ"></option> 
<option value="null">-- UNITED STATES --</option> 
<?
foreach ($statesArray as $abv => $statename)
{
    echo "<option value="$abv"";
    if($abv == $state)
    {
        echo " selected="selected">";
    }
    else
    {
        echo ">";
    }
    echo $statename . "</option>";
}
?>
</select>
I can't test that right now because I'm at school but it seems like it would work. Good luck :wink:
Post Reply