Je suis actuellement sur la création d'un forum, et j'effectue un système permettant d'indiquer si un post à été lu ou pas encore.
Voici mes requêtes permettant d'afficher l'option en ligne :
//Topic déjà consulté ?
$query=$bdd->prepare('SELECT COUNT(*) FROM forum_topic_view WHERE tv_topic_id = :topic AND tv_id = :id');
$query->bindValue(':topic',$topic,PDO::PARAM_INT);
$query->bindValue(':id',$id,PDO::PARAM_INT);
$query->execute();
$nbr_vu=$query->fetchColumn();
$query->CloseCursor();
if ($nbr_vu == 0) //Si c'est la première fois on insère une ligne entière
{
$query=$bdd->prepare('INSERT INTO forum_topic_view (tv_id, tv_topic_id, tv_forum_id, tv_post_id) VALUES (:id, :topic, :forum, :last_post)');
$query->bindValue(':id',$id,PDO::PARAM_INT);
$query->bindValue(':topic',$topic,PDO::PARAM_INT);
$query->bindValue(':forum',$forum,PDO::PARAM_INT);
$query->bindValue(':last_post',$data['topic_last_post'],PDO::PARAM_INT);
$query->execute();
$query->CloseCursor();
}
else //Sinon, on met simplement à jour
{
$query=$bdd->prepare('UPDATE forum_topic_view SET tv_post_id = :last_post WHERE tv_topic_id = :topic AND tv_id = :id');
$query->bindValue(':last_post',$data['topic_last_post'],PDO::PARAM_INT);
$query->bindValue(':topic',$topic,PDO::PARAM_INT);
$query->bindValue(':id',$id,PDO::PARAM_INT);
$query->execute();
$query->CloseCursor();
}
et lorsque j'essaye de recharger ma page pour voir si tout se passe bien une erreur survient :ma ligne 198 correspondant à 197 - $query->bindValue(':last_post',$data['topic_last_post'],PDO::PARAM_INT);Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tv_post_id' cannot be null' in /home/crobar/public_html/affichertopic.php:198 Stack trace: #0 /home/crobar/public_html/affichertopic.php(198): PDOStatement->execute() #1 {main} thrown in /home/crobar/public_html/affichertopic.php on line 198
198 - $query->execute();
Merci pour votre attention et votre aide.