Jump to content

1 question, 1 problem.


AshleyByrom

Recommended Posts

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!

 

Link to comment
https://forums.phpfreaks.com/topic/167379-1-question-1-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/167379-1-question-1-problem/#findComment-882578
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.