Sticky selection box
<p>I am trying to write a sticky selection box using HTML and PHP. I want the selections the user entered before submit to be highlighted after submit is pressed. I have tried a couple different ways and it does not seem to work. Here is the line as I have it now. </p>

<pre><code>&lt;select name="selectBox[]" multiple="multiple" size="5"&gt;
&lt;?php 
$i=0;

while($temp=mysql_fetch_array($result,MYSQL_NUM))
{
    //echo $temp[1];
?&gt;  
    &lt;option value="&lt;?php echo $temp[1] ?&gt;"
        &lt;?php if(isset($_POST[$temp[1]])) {echo "selected";} ?&gt; &gt;
        &lt;?php echo $temp[1] ?&gt; &lt;/option&gt;

&lt;?php   
    $i++;
}

?&gt;
&lt;/select&gt;
</code></pre>

<p>I know that the <code>echo "selected"</code> works because I have tried it with just that in the option tag.</p>

<p>Here is the whole code with a slightly different option tag within the selection tags but it still does not worry. </p>

<pre><code>&lt;html&gt;
&lt;head&gt;&lt;title&gt;Business Registration&lt;/title&gt;&lt;/head&gt;

&lt;body&gt;
&lt;h1&gt;
Business Registration
&lt;/h1&gt;



&lt;?php

$user="*********";
$DBserver="localhost";
$password="*********";

$myDatabase='nedwards';
$myTable1='categories';
$myTable2='businesses';
$myTable3='biz_categories';

//connect to the database server.
$con=mysql_connect($DBserver,$user,$password);

$con or die('Could not connect to MySQL: ' . mysql_error());//check connection

mysql_select_db($myDatabase) or die("Unable to select database");//select the databse we will be using
                                                                //check selection

$result = mysql_query("SELECT * FROM $myTable1");//gets the category table.... we will use the fetch_array and take the 2nd element of the array for select box

$submitted=$_POST['submitted'];

if($submitted)
{

    $sql="INSERT INTO $myTable2 (name, address, city, telephone, url) VALUES ('$_POST[bis_name]', '$_POST[addr]', '$_POST[city]', '$_POST[tele]' , '$_POST[url]')";
    mysql_query($sql, $con) or die('Error dude: ' .mysql_error());



//  echo "$_POST[bis_name]";
//  echo "$_POST[addr]";
//  echo "$_POST[city]";


    $chosenTitles=$_POST[selectBox];

    //echo "$_POST[bis_name]";

    foreach ($chosenTitles as $temp)//will run through each title chosen
    {
        //echo "$temp";//for testing

        //get cat id
        $catTitle2IDtemp=mysql_query("SELECT * FROM $myTable1 WHERE title='$temp'", $con);
        $catTitle2ID=mysql_fetch_array($catTitle2IDtemp, MYSQL_NUM);
        $catID=$catTitle2ID[0];//this is the category ID

        //get biz id
        $temp=$_POST[bis_name];
        $bis_name2IDtemp=mysql_query("SELECT * FROM $myTable2 WHERE name='$temp'", $con);
        $bis_name2ID=mysql_fetch_array($bis_name2IDtemp, MYSQL_NUM);
        $bizId=$bis_name2ID[0];//this is the biz ID


        mysql_query("INSERT INTO $myTable3 (business_id, category_id) VALUES ('$bizId', '$catID')");

    }




}



?&gt;


&lt;table border="1"&gt;


&lt;tr&gt;
&lt;td rowspan="5"&gt;
&lt;form name="input" action="&lt;?php $_SERVER['PHP_SELF'] ?&gt;" method="post"&gt; 


&lt;select name="selectBox[]" multiple="multiple" size="5"&gt;
&lt;?php 
$i=0;


while($temp=mysql_fetch_array($result,MYSQL_NUM))//gets each row of categroy table "$result" and takes second element of array $tempto select box
{
    //echo $temp[1];
?&gt;  




    &lt;option value="&lt;?php echo $temp[1] ?&gt; "    &lt;?php if(in_array($temp[1], $chosenTitles)){echo "selected";}   ?&gt;        &gt; &lt;?php echo $temp[1] ?&gt;   &lt;/option&gt;


&lt;?php   
    $i++;
}

?&gt;
&lt;/select&gt;

&lt;/td&gt;

&lt;td&gt;Buisness Name&lt;/td&gt; 
&lt;td&gt;    &lt;input type="text" name="bis_name" value="&lt;?php if($submitted==1){echo $_POST['bis_name'];}?&gt;"/&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Address&lt;/td&gt;    
&lt;td&gt;&lt;input type="text" name="addr" value="&lt;?php if($submitted==1){echo $_POST['addr'];}?&gt;" /&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;City&lt;/td&gt;   
&lt;td&gt;&lt;input type="text" name="city" value="&lt;?php if($submitted==1){echo $_POST['city'];}?&gt;"/&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Telephone&lt;/td&gt; 
&lt;td&gt;&lt;input type="text" name="tele" value="&lt;?php if($submitted==1){echo $_POST['tele'];}?&gt;"/&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;URL&lt;/td&gt;    &lt;td&gt;&lt;input type="text" name="url"  value="&lt;?php if($submitted==1){echo $_POST['url'];}?&gt;"  /&gt;&lt;/td&gt;  
&lt;/tr&gt;


&lt;input type="hidden" name="submitted" value="1"&gt;

&lt;/table&gt;

&lt;input type="Submit" value="Add Business"      /&gt;
&lt;/form&gt;





&lt;?php 
$submitted="0";
$_POST['submitted']="0";
?&gt;

&lt;/html&gt;
</code></pre>
