what is the problem here???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Nimaro
Forum Newbie
Posts: 19
Joined: Thu Nov 19, 2009 11:26 am

what is the problem here???

Post by Nimaro »

hy all,

Im trying to run a script that search a client, and then after it finds it, i want to show the values that this client have.
Im doing it like this...

Code: Select all

<?php if(isset($_POST['submit']))
{
      $nome =($_POST['nome']);
      $executa="SHOW TABLES";
      echo "<center><font face=Verdana size=2><b>Tabelas da base de dados</b></font></center><br>";
      $query = mysql_query("SELECT * FROM pacientes WHERE nome = '".mysql_real_escape_string($nome)."'");
      echo "<table>";
      while ($dados=mysql_fetch_array($query))    {
          echo "<tr><td><font face=Verdana size=2 color=#333300><B>Nome
            da tabela => $dados[0]</td></tr>";
          $executa="DESCRIBE $dados[0]";
          $aux=mysql_query($executa);
          while ($atributos=mysql_fetch_array($aux))      {
              echo "<tr><td><font face=Verdana size=1>$atributos[0]</td><td>
              <font face=Verdana size=1>| $atributos[1]</td><td>
              <font face=Verdana size=1>| $atributos[3]</td></tr>";       }
      echo "</table>";    }
}else { $nome = '';}
?>
But in this way, i got this error --->

Code: Select all

[b][i]Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Secretel\pesquisar_pacientes.php on line 18
Nome da tabela => 7[/i][/b]
Line 18 is the 2º while ->>

Code: Select all

[i][b]while ($atributos=mysql_fetch_array($aux))      {[/b][/i]
Then i put the variable aux like this --->>

Code: Select all

[b][i]$aux=mysql_query($executa) or die(mysql_error());[/i][/b]
And this error happears --->

Code: Select all

[b][i]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '7' at line 1
Nome da tabela => 7
[/i][/b]

I dont know what to do :(... can u guys help me on this? thx
User avatar
Nimaro
Forum Newbie
Posts: 19
Joined: Thu Nov 19, 2009 11:26 am

Re: what is the problem here???

Post by Nimaro »

i echo the variables and this is the result....

echo ($query); ------> Resource id #8
echo ($executa);-----> DESCRIBE 7
echo ($aux); -----> Não me imprime nada :/


The 7, represents the index that i had search...
User avatar
Nimaro
Forum Newbie
Posts: 19
Joined: Thu Nov 19, 2009 11:26 am

Re: what is the problem here???

Post by Nimaro »

SOLVED-------------------------------
------------------------------------
CODE IS HERE ;)

<?php
if(isset($_POST['submit'])){

$nome = strip_tags($_POST['nome']);
$exc = "SHOW TABLES"; /*VARIÁVEL RENOMEADA*/
$query = mysql_query("SELECT * FROM pacientes WHERE nome = '".mysql_real_escape_string($nome)."'");
echo "<center><font face=Verdana size=2><b>Tabelas da base de dados</b></font></center><br>";
echo "<table>";
while($dados = mysql_fetch_array($query)){
echo "<tr><td><font face=Verdana size=2 color=#333300><b>Nome da tabela => $dados[0]</b></td></tr>";
$executa = "$dados[0]";
$descreva = mysql_query("SELECT * FROM pacientes WHERE id = $executa");

}
while($atributos = mysql_fetch_array($descreva)){
echo "<tr><td><font face=Verdana size=1>$atributos[0]</td><td><font face=Verdana size=1>| $atributos[1]</td><td><font face=Verdana size=1>| $atributos[3]</td></tr>";
}
echo "</table>";
}else{$nome = '';}
?>
Post Reply