0

Im trying to create a form within a php while loop using echo. Following the while loop I would like to continue the form in HTML. The while loop uses a variable created by scandir() to display a list of files in a directory via a drop-down menu i.e. 'select' and 'option' tags.

The interesting bit is when I start my html again after the php loop, my browser (FIREFOX) doesn't display the first few lines of code. More specifically it doesn't recognize the lines between the comments

<!-- FROM THIS POINT --> ...code that isn't displayed... <!-- TO THIS POINT-->  

See simplified code below. Thanks in advance!

<!-- HTML... -->
<form action = "" method = "post"> 
Input File: <select name="drop_down_name" >

<?php

$dir = "/Applications/MAMP/db/mysql/IESE";
$files = scandir($dir, 1); 
$i = 0; 

while($i <= count($hypo_files)) { 
  echo "<option value = $files[$i]> $files[$i] </option>";
  $i = $i + 1;
}

?> 
<!--FROM THIS POINT -->
<fieldset>
<legend>Hypo Query:</legend>
<br>
Input Value: <!-- TO THIS POINT --> <input type = "text" name = "some_value">

3 Answers 3

2

Add an end SELECT tag.

</select>    <!-- here -->
<!--FROM THIS POINT -->
<fieldset>

Not closing tags can have weird effects like that you see with partially missing code.

Also, put your option values in quotes:

echo '<option value="'.$files[$i].'">'.$files[$i].'</option>';
Sign up to request clarification or add additional context in comments.

3 Comments

+1 correct answer. The browser is expecting <option>, <optgroup> or </select>, and OP is giving it <fieldset>...
You are a god among peasants! Thanks a billion!
Welcome! Thank me by "click to set this answer as your accepted answer" with a green check. That is how you do it here at SO.
0

you forgot to close SELECT tag. first close the SELECT tag and then try.i hope it will work. ?>

Comments

0

Your <select> tag is not getting closed. Please close that & it would work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.