Skip to content
Advertisement

Fetching values from the db; but, the selected value are not getting submitted

I have created a dynamic drop down list to fetch values from the db based on username; but, the selected drop down value does not get submitted into the db. Not sure, what I am missing here?

Here is the code snippet:

<select name="filename" id="filename" value="<?php echo $filename; ?>">
        <option> <?php
                    // Include config file
                    require_once "config.php";
                    
                    // Attempt select query execution
                    $sql = "SELECT filename FROM table WHERE username='$username'";
                    if($result = $mysqli->query($sql)){
                        if($result->num_rows > 0){
                                while($row = $result->fetch_array()){
                                   echo "<option value='' >". $row['filename'] ."</option>";}
                        } } ?>
 </option>
       
    </select>
    

Advertisement

Answer

There is no value attribute for <select> Only value attribute for <option>

Add

echo "<option value='". $row['filename'] ."' >". $row['filename'] ."</option>";}

And remove value from <select> tag

<select name="filename" id="filename">
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement