Populating a HTML form drop down menu with a PHP array

Rapinpula

New Member
I am trying to populate an HTML form's drop down list with the contents of the current directory. I attempted to use PHP's scandir() function to output these files as an array and then feed them into the option's value tag within the HTML form.I looked at various solutions available on SO and outside, but none seemed to work for me.This is how my code looks like right now:\[code\]<form action="" > <input type="submit" class="Links" value="http://stackoverflow.com/questions/13870804/Select Input"> <select > <?php $dir="./inputfiles/"; $filenames = scandir($dir); foreach($filenames as $file){ echo '<option value="' . $filenames . '">' . $filenames . '</option>'; } ?> </select> </form> \[/code\]For now I'm getting absolutely no options in the drop down menu.I am very new to PHP and would appreciate your feedback as to how to make this work. Further Changes:I tried the solutions given below, and none seemed to work. I changed the code to check whether the PHP script is able to output any variable or not in the html forms list.\[code\]<form action="" > <input type="submit" class="Links" value="http://stackoverflow.com/questions/13870804/Select Input"> <select > <?php $someval = "Video"; echo '<option http://stackoverflow.com/questions/13870804/value="value"> ' . $someval .' </option>'; ?> </select> </form>\[/code\]It displays ' . $someval .' instead of Video in the menu bar
 
Back
Top