Error duplicating the HTML form in MySQL PHP Data Search

1

I have the following problem I want to do a search in my database and display the results in the list lines, only it is giving a crazy error, it reexhibits the entire page three times, it stays like this oh:

SOMEONECanyouhelpme?
Doyouhaveanyideawhythishappens?couldhelpmewithamoreefficientcodeforthesearch?
Hereisthecompletecode:

$servidor = "localhost";
$usuario = "root";
$senha = "";
$banco = "test";
$conexao = mysql_connect($servidor, $usuario, $senha)or die("Erro: " .  mysql_error());
mysql_select_db($banco,$conexao)or die("Erro: " .  mysql_error());

$query =("SELECT cod_cliente, nome, cpf, endereco, celular FROM clientes");
// executa a query
$dados = mysql_query($query) or die(mysql_error());
// transforma os dados em um array
$linha = mysql_fetch_assoc($dados);
// calcula quantos dados retornaram
$total = mysql_num_rows($dados);
?>


	// se o número de resultados for maior que zero, mostra os dados
	if($total > 0) {
		// inicia o loop que vai mostrar todos os dados
		do {
		
?>

<!DOCTYPE html>
	<html lang="pt-br">
		<head>
			<meta charset="UTF-8"/>
			<meta charset="ISO 8859-1"/>
				<link rel="stylesheet" type="text/css" href="nocsys.css">
				
					<title>Telefonia - Consultar Cliente</title>
</head>

<body>
		<div class="containermenu"> 
			php include 'menu.php';?>
</div>

<div class="container">
<form id="contact">
			<h3>Pesquisar Cliente</h3>
				<h4>Por Favor informe os dados de forma correta!</h4>
<fieldset>
	<input name="consulta" id="consulta" maxlength="150" placeholder="nome ou cpf" type="text" tabindex="1" required autofocus>
</fieldset>

<fieldset>
      <button name="submit" id="submit" type="submit" id="contact-submit" data-submit="...Sending" action="pesquisarcliente.php" method="get">Consultar</button>
</fieldset>

<div class="containermenu"> 
<ul>
<li>
<a >Cod Cliente</a>
</li>
<li>
<a>Nome</a>
</li>
<li>
<a>CPF/CNPJ</a>
</li>
<li>
<a>Celular</a>
</li>
<li>
<BR>
<a>Endereço</a>
</li>
</ul>
<ul>
<li>
<a><a>?=$linha['cod_cliente']? = nome vindo do banco após a pesquisa</a></a>
</li>
<li>
<a><a>?=$linha['nome']?</a></a>
</li>
<li>
<a><a>?=$linha['cpf']?</a></a>
</li>
<li>
<a><a>?=$linha['celular']?</a></a>
</li>
<BR>
<li>
<a><a>?=$linha['endereco']?</a></a>
</li>
</ul>
</div>

		// finaliza o loop que vai mostrar os dados
		}while($linha = mysql_fetch_assoc($dados));
	// fim do if 
	}
?>

// tira o resultado da busca da memória
mysql_free_result($dados);
?>
<BR>
<fieldset>
      <button name="submit" id="submit" type="submit" id="contact-submit" data-submit="...Sending">Alterar</button>
</fieldset>

<BR>
<div class="container">
	<div class="row">
		<div class="col-md-10">
			<ul class="pagination">
				<li>
					<a href="#">Prev</a>
				</li>
				<li>
					<a href="#">1</a>
				</li>
				<li>
					<a href="#">2</a>
				</li>
				<li>
					<a href="#">3</a>
				</li>
				<li>
					<a href="#">4</a>
				</li>
				<li>
					<a href="#">5</a>
				</li>
				<li>
					<a href="#">Next</a>
				</li>
			</ul>
		</div>
	</div>
</div>

<fieldset>
      <button name="submit" id="submit" type="submit" id="contact-submit" data-submit="...Sending">Apagar</button>
</fieldset>
</form>
</div>
</body>
</html>

// tira o resultado da busca da memória
mysql_free_result($dados);
?>
    
asked by anonymous 24.11.2016 / 22:53

2 answers

0

create a PHP file and just write the code below:

<?php
$host   = 'localhost'; // endereço do servidor de banco de dados.
$dbname = 'nome_do_banco'; //nome de sua base de dados
$user   = 'nome_do_usuairo'; // seu usuário do banco
$pass   = 'senha'; // sua senha do banco
$pdo    = new PDO('mysql:host='.$host.';dbname='.$dbname,$user,$pass);

$pegaUsuario = $pdo->prepare('SELECT cod_cliente, nome, cpf, endereco, celular FROM clientes');
$pegaUsuario->execute();
$usuario = $pegaUsuario->fetchAll(PDO::FETCH_OBJ);

echo 'Bem vindo ' . $usuario[0]->nome;
?>

Make sure the $host, $dbname, $user and $pass data is correct.

test and see connects.

If it works, just adapt it to the code above.

    
25.11.2016 / 02:06
0

edited again

<?php
$host   = 'localhost'; // endereço do servidor de banco de dados.
$dbname = 'test'; //nome de sua base de dados
$user   = 'root'; // seu usuário do banco
$pass   = ''; // sua senha do banco
$pdo    = new PDO('mysql:host='.$host.';dbname='.$dbname,$user,$pass);

$pegaUsuario = $pdo->prepare('SELECT cod_cliente, nome, cpf, endereco, celular FROM clientes');
$pegaUsuario->execute();
$usuario = $pegaUsuario->fetchAll(PDO::FETCH_OBJ);

?>
<!DOCTYPE html>
    <html lang="pt-br">
        <head>
            <meta charset="UTF-8"/>
            <meta charset="ISO 8859-1"/>
                <link rel="stylesheet" type="text/css" href="nocsys.css">

                    <title>Telefonia - Consultar Cliente</title>
</head>

<body>
        <div class="containermenu">
        <?php include 'menu.php' ?>
</div>

<div class="container">
<form id="contact">
            <h3>Pesquisar Cliente</h3>
                <h4>Por Favor informe os dados de forma correta!</h4>
<fieldset>
    <input name="consulta" id="consulta" maxlength="150" placeholder="nome ou cpf" type="text" tabindex="1" required autofocus>
</fieldset>

<fieldset>
      <button name="submit" id="submit" type="submit" id="contact-submit" data-submit="...Sending" action="pesquisarcliente.php" method="get">Consultar</button>
</fieldset>

<div class="containermenu">
<ul>
<li>
<a >Cod Cliente</a>
</li>
<li>
<a>Nome</a>
</li>
<li>
<a>CPF/CNPJ</a>
</li>
<li>
<a>Celular</a>
</li>
<li>
<BR>
<a>Endereço</a>
</li>
</ul>
<ul>
<li>
<a><?php echo $usuario[0]->id; ?></a>
</li>
<li>
<a><?php echo $usuario[0]->nome; ?></a>
</li>
<li>
<a><?php echo $usuario[0]->cpf; ?></a>
</li>
<li>
<a><?php echo $usuario[0]->celular; ?></a>
</li>
<BR>
<li>
<a><?php echo $usuario[0]->endereco; ?></a>
</li>
</ul>
</div>

<BR>
<fieldset>
      <button name="submit" id="submit" type="submit" id="contact-submit" data-submit="...Sending">Alterar</button>
</fieldset>

<BR>
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <ul class="pagination">
                <li>
                    <a href="#">Prev</a>
                </li>
                <li>
                    <a href="#">1</a>
                </li>
                <li>
                    <a href="#">2</a>
                </li>
                <li>
                    <a href="#">3</a>
                </li>
                <li>
                    <a href="#">4</a>
                </li>
                <li>
                    <a href="#">5</a>
                </li>
                <li>
                    <a href="#">Next</a>
                </li>
            </ul>
        </div>
    </div>
</div>

<fieldset>
      <button name="submit" id="submit" type="submit" id="contact-submit" data-submit="...Sending">Apagar</button>
</fieldset>
</form>
</div>
</body>
</html>

I changed the code again and tested it on my machine with a bank I have here. if you have something wrong with the connection, check the values you are using in the host variables, dbname, etc.

    
24.11.2016 / 23:06