I'm trying to adapt to mysqli_ since mysql_ can be at any time discontinued now that new concepts like mysqli_ and pdo have appeared. I am trying to write this script that pulls the information from the database but it is not working. What could be wrong?
<select id="rsvpQuem" name="rsvpQuem">
<option value="">Selecione uma opção...</option>
<?php
$query = "SELECT * FROM tbl_convidados";
$result = $mysqli->query($query);
while($row = $result->fetch_array()){ ?>
<option value="<?=$row['id']?>"><?=$row['nome']?></option>
<?php } ?>
</select>
Leaving a solution to my problem for future reference, I ended up using PDO as indicated for security and ease. Below the code:
<select id="rsvpQuem" name="rsvpQuem">
<option value="">Selecione uma opção...</option>
<?php
$consulta = $db->prepare('SELECT * FROM tbl_convidados');
$consulta->execute();
while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) {
echo "<option value=".$linha['id'].">".$linha['nome']."</option>";
}
?>
</select>