I have a simple form with 4 choices from a database.
The form looks like this.
<form method="post" action='<?=$_SERVER[PHP_SELF]?>'>
<select name=1 onChange=this.form.submit();>
<?
$get=mysql_query("select * from Category WHERE something='$something' ");
while ($row = mysql_fetch_array($get)){$categoryid=$row['CategoryID'];
?>
<option value='<?echo $categoryid;?>' <?IF ($categoryid==$choice){echo 'selected';}?> ><?echo $categoryid;?></option>
<?}?>
</select>
</form>
<?
if($_POST){$choice=$_POST['1'];}
This lists the choices from the database, and if I echo $choice after all this it outputs the right choice as it should.
But the IF ($categoryid==$choice){echo 'selected';} doesn't work.
As I see it, it should select the choice I have just chosen but it doesn't. it selects the first choise always.
I have tried typing IF ($categoryid=='a choice'){echo 'selected';} and it works. It now selects the choice I have written.
As I said the choice is correctly outputted if I echo it at the end of the script, but if I echo it before or inside the form it outputs nothing.
So why is that.
It seems like the right data is inserted in $choice, and the IF ... "selected"... also works, but somehow $choice is empty inside the from.