1

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.

asked Mar 8, 2014 at 4:36
3
  • @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 appreciated Commented 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 us Commented 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? Commented Mar 8, 2014 at 4:44

2 Answers 2

1

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'
answered Mar 8, 2014 at 4:47
Sign up to request clarification or add additional context in comments.

Comments

0

When inserting to the database just provide the "From" or "To" field to your database. for example

$query = "SELECT * from MESSAGES where to = '$username'"

answered Mar 8, 2014 at 4:44

2 Comments

Your answer helped me, but the one above solved it. Thank you
That's okay. I'm happy my idea helped someone. :) The one with the most accurate answer will definitely get the points. :D

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.