Jump to content
Fórum Script Brasil
  • 0

No database selected


Question

Por favor me ajudem,estou com um problema serio,o erro

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\admin\categoria.php on line 51"

dai coloquei o "mysql_error" ele da "no database selected" só que ai ta a questao pois o include do conexão esta na pagina =/

o codigo é este:

categoria.php

<?php include "conexao.php" ?>
<!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>
</head>

<body>
<table width="750" border="0" align="center">
  <tr>
    <td colspan="2"><?php include('cabecalho.php'); ?></td>
  </tr>
  <tr>
    <td width="200"><?php include('menu.php'); ?></td>
    <td width="583"><table width="100%" border="0">
      <tr>
        <td> </td>
      </tr>
      <tr>
        <td align="center" style="font-size: 14px; text-align: center;"><p>categoria</p>
        
        <?php 
        
        if ($acao != "") {
            $sql = mysql_query ("SELECT * from Categoria Where id_categoria = $id"); ?>
        
            
          <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF ?>">
            <table width="300" border="1" align="center" cellpadding="2">
              <tr>
                <td width="143">Categoria</td>
                <td width="147"><label>
                  <input name="txt_categoria" type="text" id="txt_categoria" size="35" />
                </label></td>
              </tr>
              <tr>
                <td colspan="2" align="center"><label>
                  <input type="submit" name="button" id="button" value="OK" />
                </label></td>
                </tr>
            </table>
          </form>
          <?php } else { ?>
          <table width="99%" border="1">
            <tr>
              <td width="90%">Categorias</td>
              <td colspan="2" align="center">Ação</td>
              </tr>
              <?php $sql = mysql_query ("SELECT * from categorias") or exit(mysql_error());
              while ($coluna = mysql_fetch_array ($sql)) { ?>
            <tr>
              <td><?php echo $coluna[categoria] ?></td>
              <td width="5%"><img src="imagens/b_edit.gif" width="16" height="16" /></td>
              <td width="5%"><img src="imagens/b_drop.gif" width="16" height="16" /></td>
            </tr>
            <?php } ?>
            <tr>
              <td colspan="3" align="right"><img src="imagens/b_insrow.gif" width="16" height="16" /><span style="font-size: 12px;">Inserir</span></td>
              </tr>
          </table>
          <?php } ?>
          <p> </p></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="2"><?php include('rodape.php'); ?></td>
  </tr>
</table>
</body>
</html>
conexao.php
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conexao = "localhost";
$database_conexao = "loja";
$username_conexao = "root";
$password_conexao = "";
$conexao = mysql_pconnect($hostname_conexao, $username_conexao, $password_conexao) or trigger_error(mysql_error(),E_USER_ERROR); 

?>

por favor alguém me da uma luz ai

=/

Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
i aew Dimitrov adiciona isso na ultima linha do arquivo conexao.php e testa pra ver:

mysql_select_db( $database_conexao , $conexao ) or die( mysql_error() );

espero que ajude abraço!

Opa muito obrigado romerito

deu certo sim,mas você poderia me explicar porque tinha q colocar essa linha sendo q o banco já esta selecionado mais a cima??

valeu mesmo

Link to post
Share on other sites
  • 0
i aew Dimitrov adiciona isso na ultima linha do arquivo conexao.php e testa pra ver:

mysql_select_db( $database_conexao , $conexao ) or die( mysql_error() );

espero que ajude abraço!

Opa muito obrigado romerito

deu certo sim,mas você poderia me explicar porque tinha q colocar essa linha sendo q o banco já esta selecionado mais a cima??

valeu mesmo

por causa do comando mysql_select_db, ele seleciona seu banco de dados

Edited by LayonOliveira
Link to post
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.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148893
    • Total Posts
      644913
×
×
  • Create New...