-1

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.

5 Answers5

0

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>";
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
Nikhil Vaghela
  • 2,088
  • 2
  • 15
  • 30
0
{ 
     echo "<option value='{$data['title']}'>{$data['title']}</option>";
}
nospor
  • 4,190
  • 1
  • 16
  • 25
0

Use this, it's a lot easier to understand:

$title = $data['title'];
echo "<option value='{$title}'>{$title}</option>";
smottt
  • 3,272
  • 11
  • 37
  • 44
Semi-Friends
  • 480
  • 5
  • 17
0

Try this:

echo'<select name="courses[]" multiple>';    
// to hold multiple selected values name must be an array

while($data=mysqli_fetch_array($result))
{ 
    echo '<option value="'. $data['title'] .'">'. $data['title'] .'</option>';
}
echo'</select>';
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
-2

you need to use '.' for this one...

echo"<option value=' .$data[title]. '>;
fernando
  • 814
  • 1
  • 9
  • 24