Page 1 of 1

clear text box??

Posted: Fri Nov 20, 2009 9:40 am
by Nimaro
hy there,
I got 1 php page that search one client in the DB. But when i enter the page, the text box dont happear clean... they happear with this -----> <br /> <b>Notice</b>: Undefined variable: nome in <b>C:\wamp\www\Secretel\pesquisar_pacientes.php</b> on line <b>10</b><br />
Im going to show my code, hopping u can help me...

Code: Select all

<?php require_once("includes/session.php");?>
<?php require_once("includes/connection.php");?>
<?php require_once("includes/functions.php");?>
<title>Pesquisar Clientes</title>
<h1><center> Pesquisar Clientes </center></h1><br/>
<!--------PESQUISAR CLIENTES--------->
<form action="pesquisar_pacientes.php" method="post">
<table>
<tr><td>Nome:</td>
<td><input type="text" name="nome" maxlength="30" value="<?php echo htmlentities($nome); ?>"/></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Pesquisar" /></td></tr>
</table>
</form>
<form action="pesquisar_pacientes.php" method="post">
<table>
<tr><td>Telefone:</td>
<td><input type="text" name="telefone" maxlength="30" value="<?php echo htmlentities($telefone); ?>"/></td></tr>
<tr><td colspan="2"><input type="submit" name="tele" value="Pesquisar" /></td></tr>
</table>
</form>
<!----------------PESQUISA POR NOME---------->
<?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)){
$descreva = mysql_query("SELECT * FROM pacientes WHERE id='". $dados[0] ."'");
}
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[2]</td><td><font face=Verdana size=1>| $atributos[3]</td><td><font face=Verdana size=1>| $atributos[4]</td></tr>"; }
echo "</table>";
}[i]else{$nome = '';}[/i]
?>
<!----------------PESQUISA POR TELEFONE---------->
<?php if(isset($_POST['tele'])){
$telefone = strip_tags($_POST['telefone']);
$exc = "SHOW TABLES"; /*VARIÁVEL RENOMEADA*/
$query = mysql_query("SELECT * FROM pacientes WHERE telefone = ($telefone)");
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)){
$descreva = mysql_query("SELECT * FROM pacientes WHERE id='". $dados[0] ."'");
}
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[2]</td><td><font face=Verdana size=1>| $atributos[3]</td><td><font face=Verdana size=1>| $atributos[4]</td></tr>"; }
echo "</table>";
}[i]else{$telefone = '';}[/i]
?>
The code i put in Bold is where i thought it would put the text clean...
Can u tell me how can i put that texts boxes clean??

Re: clear text box??

Posted: Fri Nov 20, 2009 10:39 am
by iankent
On line 10 you do this:

Code: Select all

<?php echo htmlentities($nome); ?>
At this point, $nome hasn't been set. Same with $telefone on line 15.

You only attempt to set $nome here on line 21:

Code: Select all

$nome = strip_tags($_POST['nome']);  
You should assign $nome almost at the very top, but definately before line 10 where you attempt to use it.

And same for $telefon at line 36:

Code: Select all

$telefone = strip_tags($_POST['telefone']);
This should also be near the top, but definately before line 15 where you use it

hth

Re: clear text box??

Posted: Fri Nov 20, 2009 12:27 pm
by Nimaro
i used this code

Code: Select all

"<?php if(isset($id)){echo htmlentities($id);} ?>
and it works fine... thx ;)