I have created a page where I can edit users on a MySQL database, It prints a table with all the details of every entry (works fine) using this code:
<table border="1">
<?php
// Connect to MySQL:
$mysqlConnect = mysql_connect(localhost, <USERNAME>, <PASSWORD>);
// Select DB
mysql_select_db(<DATABASE>);
// Create query
$getUsers = 'SELECT * FROM users';
// Run query
$users = mysql_query($getUsers);
$users2 = mysql_query($getUsers);
// While statment:
while ($row = mysql_fetch_assoc($users)) {
printf("<tr><td>ID: </td><td>%s</td><td>Username: </td><td>%s</td><td>Real name: </td><td>%s</td><td>E-mail: </td><td>%s</td><td></td>Points: <td>%s</td><td>Type of User: </td><td>%s</td>", $row['id'], $row['username'], $row['name'], $row['email'], $row['points'], $row['type']);
}
?>
</table>
This all works fine! OK... now I want to create a form where you select the ID of the user from a <select> tag dynamicly filled by PHP.
This does not work... Here is the code:
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
ID: <select name="id">
<?php
while($row2 = mysql_fetch_assoc($users2)){
echo '<option value="' . $row['id'] . '">' . $row['id'] . '</option>' . "\n";
}
?>
</select>
<br />
<!-- rest of form.... -->
This comes directly after the first code snippet
I have tried using the variable "$row" (instead of $row2) in the "while()"statment and also the "$users" variable (instead of $users2)
MY PROBLEM:
The <select> box shows up as having the right number of entries, but each entry is blank:
ID: <select name="id">
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
</select>
(source code of the output)
Is there any way of sorting this out?