Re: php/mySQL and html <select>

From: Date: Sun, 06 May 2001 19:42:05 +0000
Subject: Re: php/mySQL and html <select>
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-9137@lists.php.net to get a copy of this message
Hi Nick, Assuming you have the rest of the databse interaction, all you need to is store the value of the selection (the store script will recieve a varialbe $state="AK" or whatever. To then display the users state do the following //Get the users state from the database //do this however appropiate in your code $users_state = "AK"; //(for the sake of argument) //create array of states (better way of making the form $states = array("AK","AR",....); $numstates=count($states); echo("<select name=\"state\""); for($i=0;$i<numstates;$i++) { $currstate=$states[$i]; echo("<option value=\"$currstate\"); //print first part of statement //if this option is the users add the selected keywork if($currstate==$users_state) echo(" SELECTED"); echo("> $currstate");//finish the tag } echo("</select>"); Hope this helps! Tom On Sun, 6 May 2001, Nick Terzich wrote: > hi... > > I have a user registration system that I need to add a > "state" field to. Part of the form will look something > like this but with all 50 states instead of just two: > > <form> > <select name="state"> > <option value="AK">AK</option> > <option value="AL">AL</option> > </select> > </form> > > ...how do I insert the user's state into the database > and then how do I show the user's state as the > "selected" state in the drop down list later when the > user comes back to update his/her profile? > > hope this makes sense.. thanks, > > nick > > > __________________________________________________ > Do You Yahoo!? > Yahoo! Auctions - buy the things you want at great prices > http://auctions.yahoo.com/ > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.db (#9137) next »