3
I am trying to adapt tomysqli_ sincemysql_ can be discontinued at any time now that new concepts likemysqli_ and Pdo have emerged. I am trying to write this script that pulls the database information but is not working. What may 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 queries, I ended up using PDO as indicated for security reasons 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>
Error appears?
– rray
No error appears.
– Marcos Vinicius
In select appear several rows of empty options? tested the direct query in the database?
– rray
use this class is very good. read the README and see the most basic examples. https://github.com/offboard/Class-Query
– user2321982