I am trying to query a MySQL database and display the results on a php webpage as below ,
however i get the error Parse error: syntax error, unexpected ‘position’ (T_STRING) in C:wamp64wwwwebformdisplay-data.php on line 5.Below is my PHP code
<?php
$mysqli = mysqli_connect('localhost','staff','staff','webform');
$query ="SELECT position FROM entries";
$result = $mysqli->query($query);
if($result->num_rows> 0){
$options= mysqli_fetch_all($result, MYSQLI_ASSOC);
}
<?php
<?php
include("dbconfig.php");
include("fetch-data.php");
?>
<select name="position">
<option>Select staff</option>
<?php
foreach ($options as $option) {
?>
<option><?php echo $option['position']; ?> </option>
<?php
}
?>
</select>
3
Answers
Move option tag inside your echo so it should be like this:
That should echo option tag for each $option. You can also add value attribute by adding
value='$option['position'];'
?>
I just found your problem. Just separate your file as my below code and check.