4
After fetching the data in mysql with php and displaying it on the page, I would like to know how to get these same results from this page where it is displayed and display them on another page.
<?php
//Cria a variavel telefone enviada do formulario na pagina painel.php
$telefone = $_POST['telefone'];
//Verifica se o valor de telefone não é vazio.
if (empty($telefone)) {
header("location: painel.php");
exit;
}
//Conecta com o banco e seleciona os arquivos para efetuar a contagem.
$con = mysqli_connect("localhost", "root", "", "pizzaria");
$query = mysqli_query($con, "SELECT nome, numero, endereco from clientes where telefone = $telefone");
$count = mysqli_num_rows($query);
//Se a contagem for 0
if ($count == 0) { ?>
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
Ops! não encontramos nenhum cliente com este telefone,
<a href="painel.php" class="alert-link">tente novamente!</a>
</div>
<?php
die;
//Se a contagem for 1
} else {
if ($count == 1) { ?>
<div class="alert alert-success">
Encontramos 1 cliente com este telefone!
</div>
<?php
}
}
//Mostra todos os resultados encontrados.
while ($resultado = mysqli_fetch_assoc($query)) {
echo "Cliente: ". $resultado['nome']. "<br/>";
echo "Endereço: ".$resultado['endereco']. "<br/>";
echo "N°: ".$resultado['numero']. "<br/>";
}
?>
I would like to take the results of the $result ['name'], $result['address'] and $result['number'] array and play them on the "new-request.php" page and then use them to insert into another table in the database.
using $_SESSION or sending by get or post..
– Daniel Omine
Pay attention to SQL Injection.
– lmarcelocc
will I have to create a "mini-form" to send? there is no other way?
– RFL
http://php.net/manual/en/reserved.variables.session.php
– Oeslei
only one remark:
die()
andexit()
are the same things, so why not standardize using only one of them, besides, custom usereturn;
instead ofdie()
orexit()
, because these methods were made to kill processes and not to implement output.– Ivan Ferrer