Mustafa Azad Mustafa Azad - 10 months ago 51
PHP Question

Embedding html into PHP

I have the below code

$Query='SELECT * FROM `courses`';
$result=mysqli_query($connection,$Query);
echo'<select name="courses" multiple>';
while($data=mysqli_fetch_array($result))
{ echo"<option value=\"";$data['title'];echo"\">";$data['title'];echo'</option>';}
echo"</select>";


I am trying to return values from a table,Database into a Multiple Selection menu. but it keeps giving me the below error


Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\wamp\www\ETT Logo\Controlpanel\addteacher.php on line 51


Please note that Line 51 is the line inside of the 'while' brackets.

Will Appreciate any solutions.

Answer Source

Your problem is you can not make echo option in right way. Try below code it's works for you

$Query='SELECT * FROM  `courses`';
$result=mysqli_query($connection,$Query);
echo'<select name="courses" multiple>';
while($data=mysqli_fetch_array($result)){
     echo "<option value='".$data['title']."'>".$data['title']."</option>";
}
echo"</select>";