2013-10-11 7 views
1

J'ai un problème avec la requête, quelqu'un voit quelque chose de mal?Erreur dans la requête MySQL - mots réservés

INSERT INTO messages (subject, from, recipient, text, time) 
VALUES 
('Welcome in King of the States!','The Game','$username','Hello $username, THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time') 

Erreur de sql:

#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 'from, recipient, text, time) VALUES ('Welcome in King of the States!','The Gam' at line 1 
+4

'FROM' est un mot réservé dans SQL. Vous pouvez soit y échapper avec des guillemets, soit changer le nom de la colonne. – andrewsi

+0

Ok -..- Ce sera vraiment beaucoup d'édition: DD je vais essayer que –

+0

Ok ça marche .. J'ai changé "de" à "expéditeur" et "pour" à "destinataire" Merci vous;) –

Répondre

2

from est un mot mysql réservé. essayez de placer from dans backtick

comme ci-dessous:

`from` 
+1

Oui, ça marche :) –

+0

Vous devez accepter les réponses, au lieu de changer le titre :) – WebNovice

+0

http://stackoverflow.com/help/accepted-answer – WebNovice

1

essayer de le faire:

INSERT INTO messages (`subject`, `from`, `recipient`, `text`, `time`) 
VALUES 
('Welcome in King of the States!','The Game','$username','Hello $username, THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time') 
1

De est le mot-clé de réserve dans le mysql alors utilisez la requête suivante:

INSERT INTO `messages` (`subject`, `from`, `recipient`, `text`, `time`) 
VALUES 
('Welcome in King of the States!', 
'The Game','$username', 
'Hello $username, 
THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time') 
0
"INSERT INTO messages SET subject='Welcome in King of the States!',from='The Game',recipient='".$username."',text='Hello.$username', time=''"; 
+1

Cela ne fonctionnera pas - vous avez encore besoin d'échapper à la. – andrewsi

+0

Supprimer du champ Ajouter un nom de champ de modification – Punitha

0

Instruction:

de est un mot-clé dans mysql. Donc, vous ne pouvez pas utiliser directement dans une requête comme celle-ci. Vous devez analyser chaque fois et que l'utilisation backtick

utiliser comme from