I am trying to make a drop down list which will contain as many options as there are in the database table.
$qry3 = "SELECT * FROM employees WHERE buss_id_fk = '{$_SESSION ['user_id']}' ";
$result3 = mysqli_query ( $con, $qry3);
while ($row4 = mysqli_fetch_assoc($result3)){
echo $row4['emp_id'] . " " . $row4['username'] . '</br>';
}
$qry3 is my query and it works fine with $row4 and everything shows as intended. Now when I move into my form where my drop down list should exist I made this code
<!--the list of employees the business has -->
<select name="employees" class="form-control">
<?php while ($row3 = mysqli_fetch_assoc($result3)) {
echo "<option value='" .$row3['emp_id']. "'>" .$row3['username']. "</option>" ;
} ?>
</select> <br>
my drop down list shows zero results while it should show some, just like that $row4 did. Checked a similar question where there was a typo in the code, didn't help. Thanks!
mysqliyou should be using parameterized queries andbind_paramto add user data to your query. DO NOT use string interpolation or concatenation to accomplish this because you have created a severe SQL injection bug. NEVER put$_POST,$_GETor any user data directly into a query, it can be very harmful if someone seeks to exploit your mistake.