1
This code below will print <i class="far fa-star"></i>
if the rowCount == 0
and if it is > 0
will print <i class="fas fa-check"></i>
, after the user sends the form they cannot see the <i class="fas fa-check"></i>
unless it refreshes the page, after the user sends the form the page refreshes itself, but it needs to refresh the page once more to be able to see the <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 sends the form.
EDITED, SUGGESTED BY Riscadoooooo and Scribbled
I NEED THAT <i class="fas fa-check"></i>
IS DISPLAYED IN THE FORM AFTER THE SUBMIT.
FINAL ISSUE.
So I tried it, but nothing 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 ##
}
}
Someone can help me?