I am working on a PM system and I have everything down, besides figuring out how the correct person will get the correct message.
There's this code:
$query = "SELECT to, from, rank, gender, picture, title, post FROM kaoscraft_posts WHERE to = 'username' ORDER BY msg_id DESC";
I have submitting it to the database down, and getting it, but I need to make sure the correct person gets the message.
-
@ElefantPhace I'm sorry... what more should I add in? Do I need to add the form... info on how I cna make this question better would be greatly appreciateduser3371397– user33713972014年03月08日 04:39:34 +00:00Commented Mar 8, 2014 at 4:39
-
What your actual problem is would help. When you say "I need to make sure the correct person gets the message." doesn't really mean anything to usElefantPhace– ElefantPhace2014年03月08日 04:40:51 +00:00Commented Mar 8, 2014 at 4:40
-
@ElefantPhace I see, okay. My problem is that I need to know what I should do to make the message viewable by the correct person... like, I would be able to use the user ID in other things, but the user ID isn't stored in this database. Could I use a session of username to do this?user3371397– user33713972014年03月08日 04:44:54 +00:00Commented Mar 8, 2014 at 4:44
2 Answers 2
to and from are reserved words which must be wrapped using backticks `
http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
$query = "SELECT `to`, `from`, rank, gender, picture, title, post FROM kaoscraft_posts WHERE `to` = 'username' ORDER BY msg_id DESC";
Yet, this
WHERE `to` = 'username'
may need to be
WHERE `to` = '$username'
which I suspect could be coming from a POST variable, which is not shown in your question.
If a part of your code resembles something to the effect of:
$username=$_POST['username'];
then use the following in its place:
WHERE `to` = '$username'
Comments
When inserting to the database just provide the "From" or "To" field to your database. for example
$query = "SELECT * from MESSAGES where to = '$username'"