This code will print <i class="far fa-star"></i>
if rowCount == 0
and if > 0
will print <i class="fas fa-check"></i>
, after the user submits the form they will not be able to see <i class="fas fa-check"></i>
unless it refreshes the page , after the user submits the form the page updates itself, but it needs to refresh the page one more time to be able to see <i class="fas fa-check"></i>
:
if ($rowCountFav == 0) {
$favIcon = '<i class="far fa-star"></i>';
}else{$favIcon = '<i class="fas fa-check"></i>';}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST["fav"])){
if ($rowCountFav == 0) {
$favorito = $conn->prepare("INSERT INTO 'favorito' (user_id, nameItem) VALUES (:user_id, :nameItem)");
$favorito->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$favorito->bindParam(':nameItem', $nameItem, PDO::PARAM_STR);
$favorito->execute();
}
}
}
?>
<form action="" method="post" autocomplete="off">
<button class="btnSub btnA" type="submit" name="fav" />
Favorito <?= $favIcon;?>
</button> <span class="ml-1 mr-2">-</span>
</form>
What I want : I want you to print the <i class="fas fa-check"></i>
after the user submits the form.
EDITED, SUGGESTED ScratchOoOoO and RabisCadoO
I NEED THIS <i class="fas fa-check"></i>
TO BE DISPLAYED WITHIN THE FORM AFTER SUBMIT.
END OF EDITING.
So I tried this, but nothing has changed:
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST["fav"])){
if ($rowCountFav == 0) {
$favorito = $conn->prepare("INSERT INTO 'favorito' (user_id, nameItem) VALUES (:user_id, :nameItem)");
$favorito->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$favorito->bindParam(':nameItem', $nameItem, PDO::PARAM_STR);
$favorito->execute();
}else{$favIcon = '<i class="fas fa-check"></i>';} ## eu apenas add essa linha ##
}
}
Can anyone help me?