AshleyByrom Posted July 25, 2009 Share Posted July 25, 2009 Okay well I am making a simple private messaging system where when a user creates a message that adds a row to a database then when you go on your inbox you get all the messages where read='0' (false) and touser=(their username) One question I have is in the inbox, I want a simple preview of messages I do not want to display the full message. So is there any way I can restrict the amount of characters that are displayed? Say, the first 50 or the first 100. My problem I also face is here is my query: $connectToInboxQuery = "SELECT * FROM messages WHERE touser='" . $_SESSION["theUSERNAME"] . "' AND read='0'"; and here is the MySQL error I get: 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 'read=0' at line 1 Any help is appreicated! Quote Link to comment Share on other sites More sharing options...
Coreye Posted July 25, 2009 Share Posted July 25, 2009 Try this: $connectToInboxQuery = "SELECT * FROM `messages` WHERE `touser` = '" . $_SESSION["theUSERNAME"] . "' AND `read` = '0'"; Quote Link to comment Share on other sites More sharing options...
papaface Posted July 25, 2009 Share Posted July 25, 2009 The issue is with you using mysql reserved terms in your table/db. You can see them here: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html The sticking point is your field name "read". This is a reserved name. I suggest you either do what Coreye suggested and use backticks (`) around the word read. Or change the field name from read to something that isnt a reserved term. The latter is better for compatibility as backticks are not technically valid SQL and therefore if you were to import the database into another database server you may experience issues. Quote Link to comment Share on other sites More sharing options...
AshleyByrom Posted July 25, 2009 Author Share Posted July 25, 2009 Okay, the first post freaked me out because that actually worked but I have not used backticks on any other of my querys. The second post reassured me. Thanks! I was a bit weary when using 'read' but it seemed fine. Thanks anyways! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.