4
Let’s say I have button value="+1"
on my page, and every time I click on that button is updated in the database, the page refreshes and displayed a message of success or error. This update process is simple! Only when you return from refresh the information is not updated.
Example
The field levels on the table X currently has the value of 10. I use a query and display this information! On the same page I add the button
with the code of UPDATE
, and each time I click on button
increases a level in the BD, only by clicking on this button
the page goes refresh and will display the message. But even if everything has been done optimally, the return of the information will be old, IE, still display NIVEL = 10, which has already been amended in the BD, namely the level is already equal to 11.
How then to 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();
}
?>
Puts the source code, to ensure vc need to make a new select to get the updated information.
– rray