2
How do I check if the id
user no longer has registration in the database and continue with the insert
?
if(isset($_POST['submit'])){
$comment = trim(strip_tags($_POST['comment']));
$insert = "INSERT into tb_comment (id_mark, id_user, comment, up_c, down_c, rate, active) VALUES (:post_id, :idLogged, :comment, 0, 0, :star, NOW())";
try {
$result = $conexao->prepare($insert);
$result->bindParam(':post_id', $post_id, PDO::PARAM_INT);
$result->bindParam(':idLogged', $idLogged, PDO::PARAM_INT);
$result->bindParam(':star', $star, PDO::PARAM_INT);
$result->bindParam(':comment', $comment, PDO::PARAM_STR);
$result->execute();
$count = $result->rowCount();
if($count>0){
echo '<div class="alert alert-sucess">
<strong>Sucesso!</strong> avaliação cadastrada.
</div>';
}else{
echo '<div class="alert alert-danger">
<strong>Erro ao cadastrar!</strong> Não foi possível cadastrar a avaliação.
</div>';
}
}catch(PDOException $e){
echo $e;
}
}
Ever tried to make a
select id_user from tb_comment where id_user = idLogged
and check if it returns any lines?– user28595
It is then only q I am very novice in PHP I must make the select inside the if or outside ?
– William Alvares
You want to check if
ìdLogger
exists in the bank before making the insert, correct?– user28595
Yes that’s what it is..
– William Alvares