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:
JavaScript
x
<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
JavaScript
echo "<option value='". $row['filename'] ."' >". $row['filename'] ."</option>";}
And remove value from <select> tag
JavaScript
<select name="filename" id="filename">