Select that takes mysql database options

Asked

Viewed 107 times

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)

  • ta missing * in Select-> SELECT FROM states will not work. Put SELECT * FROM states or SELECT cod_states, name FROM states

  • Would not be SELECT * FROM estados ?

  • 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?? :)

  • What version of PHP?

  • $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);

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.