简体   繁体   中英

Select correct username from database PHP MySQL

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.

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'

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM