Bonjour,

Je suis confrontée à un souci lors de l'ajout d'une fonction permettant d'ajouter des commentaires à mon blog.
J'ai un table comment contenant les champs suivants :
Nom : Capture d’écran 2019-09-27 à 10.19.24.png
Affichages : 215
Taille : 21,7 Ko

J'ai ajouté à mon modèle ceci (ma connexion à la BDD est effectuée dans une autre fonction) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
function postComment($postId, $author, $comment)
{
    $db = dbConnect();
    $comments = $db->prepare('INSERT INTO comment(FK_post, author, content, comment_date, signalement) VALUES(?, ?, ?, NOW()), false');
    $affectedLines = $comments->execute(array($postId, $author, $comment));
 
    return $affectedLines;
}
Côté contrôleur j'ai une fonction addComment :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
function addComment($postId, $author, $comment)
{
    $affectedLines = postComment($postId, $author, $comment);
 
    if ($affectedLines === false) {
        die('Impossible d\'ajouter le commentaire !');
    }
    else {
        header('Location: ./index.php?action=post&id=' . $postId);
    }
}
Mon routeur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require('./controleurs/controller.php');
 
if (isset($_GET['action'])) {
    if ($_GET['action'] == 'listPosts') {
        listPosts();
    }
    elseif ($_GET['action'] == 'post') {
        if (isset($_GET['id']) && $_GET['id'] > 0) {
            post();
        }
        else {
            echo 'Erreur : aucun identifiant de billet envoyé';
        }
    }
    elseif ($_GET['action'] == 'addComment') {
        if (isset($_GET['id']) && $_GET['id'] > 0) {
            if (!empty($_POST['author']) && !empty($_POST['comment'])) {
                addComment($_GET['id'], $_POST['author'], $_POST['comment']);
            }
            else {
                echo 'Erreur : tous les champs ne sont pas remplis !';
            }
        }
        else {
            echo 'Erreur : aucun identifiant de billet envoyé';
        }
    }
}
else {
    listPosts();
}
Et voici le formulaire dans ma vue :
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<form action="index.php?action=addComment&amp;id=<?= $post['id'] ?>" method="post">
                        <div>
                            <label for="author">Auteur</label>
                            <br />
                            <input type="text" id="author" name="author" />
                        </div>
                        <div>
                            <label for="content">Commentaire</label>
                            <br />
                            <textarea id="content" name="content"></textarea>
                        </div>
                        <div>
                            <input type="submit" />
                        </div>
                    </form>

Lors de la soumission du formulaire, j'obtiens juste une page blanche..
Voilà voilà, si quelqu'un peut m'éclairer