Remembering users choices in drop down lists (form)

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
agebpt
Forum Newbie
Posts: 7
Joined: Tue Sep 01, 2009 5:08 am

Remembering users choices in drop down lists (form)

Post by agebpt »

Hello all,

I've been building a CMS system and have virtually completed it - when the client wants to edit something from the database, say a case study, they select edit and are met with a standard html form to fill in and update the details. I'm pulling in the existing details for the case study into the form choices as follows:

Code: Select all

 
<?php
            
    //connect to database
    mysql_pconnect ($host, $user, $pass) or die ("Login info is incorrect") ; 
    mysql_select_db ($database);
            
        //selects everything from the table and puts it in to $result variable  
    $result = mysql_query("SELECT * FROM $tableTen WHERE id=" . $_GET['id']);
    $data = mysql_fetch_array($result);
        
        <form input section......
        <input type="text" tabindex="1" name="casestudy_name" value="<?php echo $data['name']  ?>" style="width:245px" />
        <textarea name="casestudy_information" tabindex="3" rows="12" cols="50" style="width:450px"><?php echo $data['information'] ?></textarea>
 
        etc etc                 
?>
 
...so using the $data variable to fill out the form - my problem comes when I have a drop down list of 6 options, where they choose the section they wish to put the case study in. There's a choice of 6 in the drop down list as follows:

Code: Select all

 
<select name="client_id">
         <option value="0">Choose section...</option>
         <option value="1">section 1</option>
         <option value="2">section 2</option>
         <option value="3">section 3</option>
         <option value="4">section 4</option>
         <option value="5">section 5</option>
         <option value="6">section 6</option>
</select>
 
What I really need is a way of the drop down list remembering which section the case study is associated with, to go with the existing content being displayed in the various form fields on the rest of the form - does anyone know how to do this, as I can't see an obvious solution - I need the values to be 1,2,3,4,5,6 and the words in between to be certain sections.

Cheers
agebpt
Forum Newbie
Posts: 7
Joined: Tue Sep 01, 2009 5:08 am

Re: Remembering users choices in drop down lists (form)

Post by agebpt »

Anyone have any ideas?

Still not managed to work it out...
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Remembering users choices in drop down lists (form)

Post by josh »

set the selected attribute
Post Reply