Why does my select option not display the number in the dropdown select? What's wrong?
<?php
$query = "SELECT * FROM users";
$result = mysqli_query($mysqli, $query);
if(!$result){
die('Query FAILED');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div class="container">
<div class="col-xs-6">
<form action="login_create.php" method="post">
<div class="form-group">
<label for="username">Username</label>
<input type="text" name="username" class="form-control"/>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" class="form-control">
</div>
<div class="form-group">
<select name="id" id = " ">
<?php
while($row = mysqli_fetch_assoc($result)){
$id = $row['id'];
echo "<option value='$id'>$id</option>";
}
?>
</select>
</div>
<input class="btn btn-primary" type="submit" name="submit"
value="UPDATE">
</form>
</div>
</div>
</body>
</html>
Are you connected to the DB, what's this value
$mysqli
It's never defined/set in your post. Therefore I have to assume you never connected to the DB.
First place to start always, is turn on error reporting
<?php
ini_set('display_errors', 1);
error_reporting(-1); //or E_ALL
... other code ...
If you do that and it says, something like.
Warning undefined variable $mysql
Then you will know.
You must call Database connection...
Replace
DATABASE with Database name
$mysqli = new mysqli('LOCALHOST','USERNAME','PASSWORD','DATABASE')
$query = "SELECT * FROM users";
$result = mysqli_query($mysqli, $query);
if(!$result){
die('Query FAILED');
}