Voilà maintenant deux jours que je rencontre un problème qui pourrait bien avoir raison de ma santé mentale.
J'ai construit une fonction permettant d'ajouter des commentaires sur un 'blog' de chat.
Voici la fonction (model)
Code : Tout sélectionner
function writeComments($postId,$pseudonyme,$comment)
{
$db = dbConnect();
$req = $db ->prepare('INSERT INTO Comments (author,comment,id_post,date_content) VALUES (?,?,?,NOW()');
$req ->execute(array($pseudonyme,$comment,$postId));
}
Code : Tout sélectionner
function writeoncomments()
{
$pseudonyme = $_POST['pseudo'];
$comment = $_POST['comment'];
$postId = $_GET['id'];
writeComments($postId,$pseudonyme,$comment);
require('/opt/lampp/htdocs/workphp/MCVact/view-1.php');
}voici la fonction(routeur)
Code : Tout sélectionner
elseif ($_GET['action'] == 'post')
{
if (isset($_POST['comment']) AND isset($_POST['pseudo']))
{
if (($_POST['comment'] && $_POST['pseudo']) > 0)
{
writeoncomments();
}
}
}Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 in /opt/lampp/htdocs/workphp/MCVact/models/model.php:48 Stack trace: #0 /opt/lampp/htdocs/workphp/MCVact/models/model.php(48): PDOStatement->execute(Array) #1 /opt/lampp/htdocs/workphp/MCVact/controllers/control.php(20): writeComments('2', 'SAlut', 'sa toi ') #2 /opt/lampp/htdocs/workphp/MCVact/rooter.php(25): writeoncomments() #3 {main} thrown in /opt/lampp/htdocs/workphp/MCVact/models/model.php on line 48
J'avoue ne pas comprendre d'ou vient l'erreur,
Merci d'avance pour votre aide précieuse.