Bonjours,
J'ai réalisé un mini chat pour m'amuser, cependant, une requête semble poser problème. Voici le code source de la page minichat.php :

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
    session_start();
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="minichat.css" />
        <title>Mini-chat</title>
    </head>
    <body>
 
        <!-- formulaire !-->
 
        <?php
            if(!isset($_SESSION['pseudo']))
            {
        ?>
                <form action="minichat_post.php" method="post">
                    <p>
                        <label for="pseudo">Votre pseudo : </label><input type="text" id="pseudo" name="pseudo" maxlength="255" /><br />
                        <label for="message">Votre message : </label><input type="text" id="message" name="message" maxlength="255" /><br />
                        <input type="submit" />
                    </p>
                </form>
        <?php
            }
            else
            {
        ?>
            <form action="minichat_post.php" method="post">
                    <p>
                        <label for="pseudo">Votre pseudo : </label><input value="<?php echo $_SESSION['pseudo'];?>" type="text" id="pseudo" name="pseudo" maxlength="255" /><br />
                        <label for="message">Votre message : </label><input type="text" id="message" name="message" maxlength="255" /><br />
                        <input type="submit" />
                    </p>
            </form>
        <?php
            }
 
        // connexion
 
            try
            {
                $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
                $bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '', $pdo_options);
 
        //Selection pages de l'historique
 
                $reponse2 = $bdd->query('SELECT count(message) as nombre FROM minichat');
 
                $nombreEntrer = $reponse2->fetch();
                $nombre = ceil($nombreEntrer['nombre'] / 10);
 
                $reponse2->closeCursor();
        ?>
                <form action="minichat.php" method="get">
                    <p>
                        <label for="page">Selectionnez la page désirée pour l'historique : </label>
                        <select id="page" name="page">
        <?php
                            for($i = 1; $i <= $nombre; $i++)
                            {
                                $j = $i - 1;
        ?>
                                <option value="<?php echo $j . '0';?>"><?php echo $i ;?></option>
        <?php
                            }
        ?>
                        </select> <input type="submit" />
                    </p>
                </form>
        <?php
 
        // Affichage
 
                if(isset($_GET['page']))
                {
                    $reponse = $bdd->prepare('SELECT * FROM minichat ORDER BY id DESC LIMIT ?, 9');
                    $reponse->execute(array($_GET['page']));
                }
                else
                {
                    $reponse = $bdd->query('SELECT * FROM minichat ORDER BY id DESC LIMIT 0, 9');
                }
                while($contenue = $reponse->fetch())
                {
        ?>
                    <table>
                        <tr>
                            <td><?php echo strip_tags($contenue['pseudo']);?></td>
                            <td><?php echo strip_tags($contenue['message']);?></td>
                        </tr>
                    </table>
        <?php
                }
                    $reponse->closeCursor();
            }
            catch(Exception $e)
            {
                die('Erreur : ' . $e->getMessage());
            }
        ?>
        <p><a href="minichat.php">Cliquez ici pour actualiser...</a></p>
    </body>
</html>
La requête dans la condition
Code : Sélectionner tout - Visualiser dans une fenêtre à part
if(isset($_GET['page']))
semble poser problème :

Erreur : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''00', 9' at line 1