0
So I have this code here and I don’t understand why it’s not working.
I’m a beginner in PHP and I can’t make it work.
// a conexão com o banco está em outro aquivo, por isso não achei necessário inclui-la aqui
<select id="txt-model" class="field-50" name="estados">
<option>Selecione um estado</option>
<?
$sql = "SELECT FROM estados";
$result = mysql_query($sql);
while($option = mysql_fetch_array($result)) {
$estado = $option["nome"];
$id = $option["cod_estados"];
echo "<option id=".$id.">".$estado."</option>";
};
?>
</select>
I think functions
mysql_*
no longer exist, in the latest version of PHP (correct me if I’m wrong)– Artur Trapp
ta missing * in Select-> SELECT FROM states will not work. Put SELECT * FROM states or SELECT cod_states, name FROM states
– Rovann Linhalis
Would not be
SELECT * FROM estados
?– Thiago
Pow, I tried to put the *, which I had forgotten msm, and it wasn’t, and I tried the SELECT cod_states, name FROM states and also wasn’t, someone else?? :)
– FiREBiRD
What version of PHP?
– Don't Panic
$query = "SELECT * FROM states"; $result = mysql_query($query); if (!$result) { $message = 'Invalid query: ' . mysql_error() . " n"; $message .= 'Whole query: ' . $query; die($message); } while ($Row = mysql_fetch_assoc($result)) { echo $Row['name']; echo $Row['cod_states']; mysql_free_result($result result);
– Don't Panic