Erreur SQL syntax

Par DayTech, il y a 9 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

Je suis entrain de regarder la vidéo pour créer un tchat en PHP & EN AJAX. Tout fonctionne bien jusqu'à que je fasse la requête SQL :

<?php $sql = "SELET * FROM messages ORDER BY date DESC LIMIT 15"; $req = mysql_query($sql) or die(mysql_error()); while($data = mysql_fetch_assoc($req)){ ?> <p><strong><?php echo $data['pseudo']; ?></strong> : <?php echo htmlentities($data['message']); ?></p> <?php } ?>

Le message d'erreur :

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 'SELET * FROM messages ORDER BY date DESC LIMIT 15' at line 1

Voici tout mon code :

<?php include("connect.php"); ?> <?php session_start(); if(!isset($_SESSION['pseudo']) || empty($_SESSION['pseudo'])){ header('Location:index.php'); } ?> <!DOCTYPE html> <html> <head> <title>TCHAT EN PHP & EN AJAX</title> <link rel="stylesheet" type="text/css" href="tchat.css"> <meta charset="UTF-8"> </head> <body> <header> <ul> <span style="font-size:2em;font-family:Verdana;color:#fff;">MON TCHAT</span> </ul> </header> <ul> Bienvenue <?php echo $_SESSION['pseudo']; ?> ! </ul> <div id="tchat"> <?php $sql = "SELET * FROM messages ORDER BY date DESC LIMIT 15"; $req = mysql_query($sql) or die(mysql_error()); while($data = mysql_fetch_assoc($req)){ ?> <p><strong><?php echo $data['pseudo']; ?></strong> : <?php echo htmlentities($data['message']); ?></p> <?php } ?> </div> <hr /> <form action="#" method="post" style="margin:10px;"> <textarea name="message" style="width:100%;"> </textarea> <input type="submit" value="Tchatter"/> </form> </body> </html>

J'aimerais savoir pourquoi ca ne marche pas SVP :'(

Bien cordialement, DayTech

4 réponses

AlexJM, il y a 9 ans

Salut, tu as écrit SELET au lieu de SELECT

brokleen, il y a 9 ans

Mec t sérieux ?
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 'SELET * FROM messages ORDER BY date DESC LIMIT 15' at line 1

SELET ? le système mâche tout le boulot, et on prend même pas deux minutes pour lire.

brokleen, il y a 9 ans

@AlexJm petit cachotié

DayTech, il y a 9 ans

Salut, merci pour vos réponses. Je pense que j'avais la tête ailleurs xD Encore merci et désolé pour le dérangement ! :)