Problem with data in forms

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
cardsup
Forum Newbie
Posts: 2
Joined: Mon Jul 25, 2005 4:22 pm

Problem with data in forms

Post by cardsup »

Hi,

I have a problem. I am a PHP novice, and I am trying to modify a script to better fit a client's needs.

Here is the problem. When a user creates a profile using the PHP script, all data is entered into MySQL database. When the user wants to update the info, he/she goes to a page where the previous information is pre-entered (from the database). However, some of the forms (drop down menus, etc) do not use the database information...I wonder why does that happen?

Here is a sample code I use:

Code: Select all

<tr>
	<td align=right>Sign:</td>
	<td>
		<select name="sign">
			<option value=""></option>
			<option value="Aries" <?=$sstatus1?>>Aries</option>
			<option value="Taurus" <?=$sstatus2?>>Taurus</option>
			<option value="Gemini" <?=$sstatus3?>>Gemini</option>
			<option value="Cancer" <?=$sstatus4?>>Cancer</option>
			<option value="Leo" <?=$sstatus5?>>Leo</option>
			<option value="Virgo" <?=$sstatus6?>>Virgo</option>
			<option value="Libra" <?=$sstatus7?>>Libra</option>
			<option value="Scorpio" <?=$sstatus8?>>Scorpio</option>
			<option value="Sagittarius" <?=$sstatus9?>>Sagittarius</option>
			<option value="Capricorn" <?=$sstatus10?>>Capricorn</option>
			<option value="Aquarius" <?=$sstatus11?>>Aquarius</option>
			<option value="Pisces" <?=$sstatus12?>>Pisces</option>
		</select>
	</td>
</tr>
I hope I am clear enough, but if not I apologize.

d11wtq | Please use

Code: Select all

tags to post PHP code [/color]
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

What are the values $sstatus1-12?

Try something like this:

Code: Select all

<option value="Aries" <? echo $sign=='Aries'?' selected':'';?>>Aries</option>
cardsup
Forum Newbie
Posts: 2
Joined: Mon Jul 25, 2005 4:22 pm

Post by cardsup »

Thanks, I tried it but it did not work...It goes to the first value...

Here is the changed code I used:

Code: Select all


&lt;tr&gt;
	&lt;td align=right&gt;Sign:&lt;/td&gt;
	&lt;td&gt;
		&lt;select name=&quote;sign&quote;&gt;
			&lt;option value=&quote;&quote;&gt;&lt;/option&gt;
            &lt;option value=&quote;Aries&quote; &lt;? echo $sign=='Aries'?' selected':'';?&gt;&gt;Aries&lt;/option&gt; 
			&lt;option value=&quote;Taurus&quote; &lt;? echo $sign=='Taurus'?' selected':'';?&gt;&gt;Taurus&lt;/option&gt;
			&lt;option value=&quote;Gemini&quote; &lt;? echo $sign=='Gemini'?' selected':'';?&gt;&gt;Gemini&lt;/option&gt;
			&lt;option value=&quote;Cancer&quote; &lt;? echo $sign=='Cancer'?' selected':'';?&gt;&gt;Cancer&lt;/option&gt;
			&lt;option value=&quote;Leo&quote; &lt;? echo $sign=='Leo'?' selected':'';?&gt;&gt;Leo&lt;/option&gt;
			&lt;option value=&quote;Virgo&quote; &lt;? echo $sign=='Virgo'?' selected':'';?&gt;&gt;Virgo&lt;/option&gt;
			&lt;option value=&quote;Libra&quote; &lt;? echo $sign=='Libra'?' selected':'';?&gt;&gt;Libra&lt;/option&gt;
			&lt;option value=&quote;Scorpio&quote; &lt;? echo $sign=='Scorpio'?' selected':'';?&gt;&gt;Scorpio&lt;/option&gt;
			&lt;option value=&quote;Sagittarius&quote; &lt;? echo $sign=='Sagittarius'?' selected':'';?&gt;&gt;Sagittarius&lt;/option&gt;
			&lt;option value=&quote;Capricorn&quote; &lt;? echo $sign=='Capricorn'?' selected':'';?&gt;&gt;Capricorn&lt;/option&gt;
			&lt;option value=&quote;Aquarius&quote; &lt;? echo $sign=='Aquarius'?' selected':'';?&gt;&gt;Aquarius&lt;/option&gt;
			&lt;option value=&quote;Pisces&quote; &lt;? echo $sign=='Pisces'?' selected':'';?&gt;&gt;Pisces&lt;/option&gt;
		&lt;/select&gt;
	&lt;/td&gt;
&lt;/tr&gt;
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Set the variable 'sign' equal to the value of the item you want selected.
Post Reply