Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Fatal error com a função mysql_fetch()


Pedro Augusto

Question

Olá, estou tentando exibir a informação do bd que for solicitada no formulário. Mas dá esse erro:

Fatal error: Call to undefined function mysql_fetch() in /home/batistas/public_html/test/03.php on line 20.

A linha 20 é: while($linha = mysql_fetch_array($query))

Alguém sabe o que é???

<form name="choose" method="post" action="?acao=show">
<select name="nid">
      <option value="4">Um</option>
      <option value="11">Dois</option>
      <option value="12">Três</option>
<input type="submit" value="Abrir">
</form>
<?
        include('config.php');

        if($_GET['acao'] == "show") {
            mysql_connect("$dbhost","$dbuser","$dbpass");
             mysql_select_db("$dbname");

              $nid = $_POST['nid'];
            $sql = mysql_query("SELECT * FROM noticias WHERE id='$nid'");

            $query = mysql_query($sql);

    while($linha = mysql_fetch_array($query))
    {
        # Mostra os dados que estao no Banco de Dados
        echo "<p><b>" . $linha["id"] . " | " . $linha["titulo"] . "</b><br /><i>" . $linha["data"] . " - " . $linha["hora"] . "</i></p>
        <p>" . $linha["corpo"] . "</p>
        <p><input type='hidden' name=\"id\" value=\"" . $linha["id"] . "\"></p>";
    }
    }
?>

Obrigado desde já... Pedro Augusto

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Beleza, agora está tudo ok! Muito obrigado... O código corrigido ficou assim:

<form name="choose" method="post" action="?acao=show">
<select name="nid">
      <option value="4">Um</option>
      <option value="11">Dois</option>
      <option value="12">Três</option>
<input type="submit" value="Abrir">
</form>
<?
        include('config.php');

        if($_GET['acao'] == "show") {
            mysql_connect("$dbhost","$dbuser","$dbpass");
             mysql_select_db("$dbname");

              $nid = $_POST['nid'];
            $sql = mysql_query("SELECT * FROM noticias WHERE id='$nid'");

            while($linha = mysql_fetch_array($sql))
    {
        # Mostra os dados que estao no Banco de Dados
        echo "<p><b>" . $linha["id"] . " | " . $linha["titulo"] . "</b><br /><i>" . $linha["data"] . " - " . $linha["hora"] . "</i></p>
        <p>" . $linha["corpo"] . "</p>
        <p><input type='hidden' name=\"id\" value=\"" . $linha["id"] . "\"></p>";
    }
    }
?>

Link to comment
Share on other sites

  • 0

Eu ainda colocaria um If ai p/ evitar qlqr tipo de erro..

ASSIM:

<form name="choose" method="post" action="?acao=show">
<select name="nid">
      <option value="4">Um</option>
      <option value="11">Dois</option>
      <option value="12">Três</option>
<input type="submit" value="Abrir">
</form>
<?
        include('config.php');

        if($_GET['acao'] == "show") {
            mysql_connect("$dbhost","$dbuser","$dbpass");
             mysql_select_db("$dbname");

              $nid = $_POST['nid'];
            $sql = mysql_query("SELECT * FROM noticias WHERE id='$nid'");

          if(mysql_fetch_array($sql)){
            $sql = mysql_query("SELECT * FROM noticias WHERE id='$nid'");
            while($linha = mysql_fetch_array($sql)) {
                  # Mostra os dados que estao no Banco de Dados
                  echo "<p><b>" . $linha["id"] . " | " . $linha["titulo"] . "</b><br /><i>" . $linha["data"] . " - " . $linha["hora"] . "</i></p>
                  <p>" . $linha["corpo"] . "</p>
                  <p><input type='hidden' name=\"id\" value=\"" . $linha["id"] . "\"></p>";
            }
           }
    }
?>

Pelo menos assim evita qlqr erro... Pode colocar um else p/ exibir uma msg tipo "nenhum dado encontrado" ou coisa do tipo...

Edited by Evandro Fontes
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152k
    • Total Posts
      651.5k
×
×
  • Create New...