I would like to edit a form which I already store the real value for the combo box. Then during editing session, it start reseting the combo box to the top list.


//Load Student Profile
    if (!empty($_GET['student_id'])){
        $result = mysql_query("SELECT * FROM student WHERE student_id =".$_GET['student_id']) or die(mysql_error());
        $data = mysql_fetch_array($result);
        $student_id = $data['student_id'];
        $stu_fname = $data['stu_fname'];
        $stu_lname = $data['stu_lname'];
        $stu_email = $data['stu_email'];
        $stu_address = $data['stu_address'];
        $stu_telp = $data['stu_telp'];
        $stu_hp = $data['stu_hp'];
        $stu_wa = $data['stu_wa'];
        $stu_skype = $data['stu_skype'];
        $stu_facebook = $data['stu_facebook'];
        $stu_twitter = $data['stu_twitter'];
        $stu_picture = $data['stu_picture'];
        $newfilename = $data['newfilename'];
        $access_level_id = $data['access_level_id'];
    else {
    //echo "unable to select data".'<br>';
    //echo "student_id is empty";
    <div align="center">
        <div style="width:800px;text-align:left;">
        <?php echo $confirmation;?>
        <?php //echo $confirmation2;?>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF'] .'?student_id='. $student_id;?>" enctype="multipart/form-data">
            <!-- <input type="hidden" name="id" value="<?php// echo $id; ?>"/>-->
                    <td>Student Picture</td>              
                    <?php echo "<img src='../upload/".$newfilename."'>"; ?><br>
                    <input type="file" value="upload" name="file"/><br><br>
                    <td>Group Name</td>               

                    $rs = mysql_query("SELECT * FROM `group`") or die(mysql_error());                   
                    echo "<select name='group_id'>";
                    while($data = mysql_fetch_array($rs)){
                        echo "<option value='".$data['group_id']."'>".$data['group_name']."</option>";
                    echo "</select>";


                    echo "<select name='access_level_id'>";
                        echo "<option value='3'>".'Student'."</option>";
                        echo "<option value='4'>".'Student Group Master'."</option>";
                    echo "</select>";


Check access! How to lock the access so that it shows the value that I have stored in the database(Student Group Master) instead of reseting the value to the top list (Student) ?

2 Years
Discussion Span
Last Post by almostbob

*note: can someone moves this article to php forum? I forget to change the forum name.

 echo '<select name="access_level_id">';
 echo '<option value="3">Student</option>';
 echo '<option value="4">Student Group Master</option>';
 echo '</select>';} 
else {echo "Access level $data['access_level_id']';} ?>

If not set, display select box,
if set, display setting
If not the correct index from the$data array, you probably know the correct index,

echo '<select name="access_level_id">';
echo '<option value="3" ';
 if($data['access_level_id'])=='3'{echo 'selected="selected" ';}
echo '>Student</option>';
echo '<option value="4" ';
 if($data['access_level_id'])=='4'{echo 'selected="selected" ';}
echo '>Student Group Master</option>';
echo '</select>';  ?>

populate the selected option, with selected

either way works, the second is better if the editing may involve changing access levels. the first is better if the editor is not permitted to change access levels

Dquotes are parsed for php commands, its better to use single quotes if there is no php in the echoed text

Edited by almostbob

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.