0
I need to submit a POST form to make a query on a PHP page (dashboard.php) and return the results of that query, on that same page of the form (refresheless), how could you do?
I imagine I’ll have to use Ajax, but I don’t know how...
The code I have, it’s working, I’ve used SESSION
, however, is giving refresh on the page.
HTML: (dashboard.php)
<form method="post" action="verificar-painel-admin.php">
<input type="text" name="usuario" value="joaozinho" readonly>
<button type="submit" name="confirm_usuario_pedido">Clique aqui para consultar os pedidos desse usuário.</button>
</form>
<p>
<div class="card-deck">
<?php
// Exibindo os pedidos do cliente caso haja.
if(isset($_SESSION['msg_pedidos_usuario'])){
echo $_SESSION['msg_pedidos_usuario'];
unset($_SESSION['msg_pedidos_usuario']);}
?>
</div>
</p>
PHP: (check-panel-admin.php)
if(isset($_POST['confirm_usuario_pedido'])){
$cliente = $_POST['cliente'];
// Todos os pedidos do usuário
$sql = mysqli_query($con,"SELECT ID_compras FROM usuarios_pedidos WHERE usuario = '$cliente'");
$qnt_pedidos = mysqli_num_rows($sql);
// Se existir pedido desse usuário, exibir.
if ($qnt_pedidos > 0) {
while ($cont = mysqli_fetch_array($sql)){
$_SESSION['msg_pedidos_usuario'] = "Você possui ". $qnt_pedidos . "pedidos";
} } // End IF & While
else{
$_SESSION['msg_pedidos_usuario'] = "<h4>Você ainda não possui pedidos!</h4>";
}
header("Location: painel-admin.php");
}
Thank you so much for the answer! but unfortunately I am layman with
ajax, json, etc...
, I don’t really know how to do it. If it’s not too much to ask, wouldn’t you be able to give more detailed examples based on my code? Since how I send the data fromform
, until the recovery of the same?– Web Developer
No problem, there is, but is there any way we can talk through a chat? Because it will probably be very long
– andre_luiss
I don’t think I got enough scores
– Web Developer
And I don’t know how to make kkkk has my Linkedin in my profile, sends me a message there and we try to see it there
– andre_luiss
Good Answer, there are also other libraries like Axios or you can call natively with Xmlhttprequest or with the new fetch().
– Robson Piere