Let's say I have button value="+1"
on my page, and every time I click on this button an update is made to the database, the page refreshes and displays a message of success or error. This update process is simple! Only when returning from refresh the information is not updated.
Example
The levels field in the X table currently has a value of 10. I use a query and display this information! In that same page I add button
with the code of UPDATE
, and every time I click on button
it increases one level in the DB, only that by clicking on this button
the page goes from refresh and will display the message . But even if everything has happened ideally, the return of the information will be old, that is, it will still display LEVEL = 10 , and has already been changed in the DB, in> is already equal to 11.
How can you make the return of this information already "current"?
<?php
include_once("head.php");
$ID = 1;
$niveis = $pdo->prepare("SELECT * FROM x WHERE ID = ?");
$niveis->bindValue(1, $ID, PDO::PARAM_INT);
$niveis->execute();
$niveis_dados = $niveis->fetchObject();
?>
NIVEL ATUAL: <?php echo $niveis_dados->NIVEL ?>
<div class="DA">Aumentar/Diminuir : </div>
<div class="DB">
<form method="post" enctype="multipart/form-data">
<button value="1" name="UPDOWN" type="submit">+</button>
<button value="-1" name="UPDOWN" type="submit">-</button>
</form>
</div>
</div>
<?php
//CODIGO DE UPDATE DO NIVEL
if(isset($_POST['UPDOWN']))
{
//AUMENTAR ou DIMINUIR
$UPDOW = $_POST['UPDOWN'];
//NOVO NIVEL
$novo_nivel = $niveis_dados->NIVEL + $UPDOW;
echo "Novo nivel: ".$novo_nivel;
//UPDATE 1 ::: NOVO NIVEL
$up_props = $pdo->prepare("UPDATE x SET NIVEL = :1 WHERE ID = :2");
$up_props->bindParam(":1", $novo_nivel , PDO::PARAM_INT);
$up_props->bindParam(":2", $ID , PDO::PARAM_INT);
$up_props_executa = $up_props->execute();
}
?>