Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) @Ajuda: Warning: mysql_fetch_array() expects parameter 1 t


Nukes

Pergunta

Galera, to com um problema aqui, será que alguém pode ajudar?

To tentando listar uma categoria de produtos numa tabela e tá me retornando o erro:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\webserver\www\GigaWare\Admin\categoria.php on line 59
E o notice:
Notice: Undefined variable: acao in C:\webserver\www\GigaWare\Admin\categoria.php on line 34
O código é o seguinte:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body table tr td table tr th {
    text-align: center;
    font-size: 12px;
    font-family: Arial, Helvetica, sans-serif;
}
body table tr td table tr th table tr td {
    text-align: center;
}
</style>
</head>

<body>
<table width="750" align="center" border="0">
  <tr>
    <th colspan="2" scope="col"><?php include "cabecalho.php"; ?></th>
  </tr>
  <tr>
    <th width="200" scope="row"><?php include "menu.php"; ?></th>
    <td width="575"><table width="100%" border="0">
      <tr>
        <th scope="col">&nbsp;</th>
      </tr>
      <tr>
        <th scope="row"><p>Adicionar Categorias</p>
        
        <?php

         if ($acao != "") {
            $sql = mysql_query("SELECT * from Categoria Where id_categoria = ($id)") 
        
        ?>
                
          <form id="form1" name="form1" method="post" action="">
            <table width="300" border="1" align="center" cellpadding="0">
              <tr>
                <th width="127" scope="col">Categoria:</th>
                <th width="163" scope="col"><label for="txt_categoria"></label>
                  <input name="txt_categoria" type="text" id="txt_categoria" size="35" maxlength="35" /></th>
              </tr>
              <tr>
                <th colspan="2" scope="row"><input type="submit" name="button" id="button" value="Inserir" action="" /></th>
                </tr>
            </table>
          </form>
            <?php } else {?>
          <table width="99%" border="1">
            <tr>
              <th width="84%" scope="col">Categorias</th>
              <th colspan="2" scope="col">Ação</th>
              </tr>
              
            <?php $sql = mysql_query("select * from categorias");
            while ($coluna = mysql_fetch_array($sql)) { ?>
            <tr>
              <th scope="row"><?php echo $coluna[categoria] ?></th>
              <td width="8%"><img src="../Imagens/Editar.gif" width="21" height="21" /></td>
              <td width="8%"><img src="../Imagens/ico_excluir.gif" width="20" height="20" /></td>
            </tr>
            <?php } ?>
            <tr>
              <th scope="row">&nbsp;</th>
              <td colspan="2"><img src="../Imagens/ic-inserir.gif" width="21" height="22" /></td>
              </tr>
          </table>
          <?php } ?>
          </th>
      </tr>
    </table></td>
  </tr>
  <tr>
    <th colspan="2" scope="row"><?php include "rodape.php"; ?></th>
  </tr>
</table>


</body>
</html>

Será que alguém pode me dar uma luz?

Ps: To iniciando agora no PHP, se possível um pouco mastigado...

Obrigado desde já!

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

Galera, depois de muito quebrar a cabeça, fiz o seguinte:

No MySql query mudei

<?php $sql = mysql_query("select * from categorias");
Por
<?php $sql = mysql_query("select * from categorias") or die ("Erro no MySQL_query: $query. ".mysql_error());

Isso me retornou o erro que estava dando: Não tinha conexão com o banco de dados.

Revisando o código, vi que simplesmente esqueci de dar include no conexão.php.

Como eu disse, sou iniciante!

hehe

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...