开发者

How to use three conditions in WHERE clause of mysql query?

Here is my current MySQL syntax (but this doesn't work):

SELECT * FROM posts WHERE userID = $userID AND postBy = $postBy AND po开发者_StackOverflow中文版stType = 'unread'

Here is the picture of my MySQL table (a picture can show more than words!)

How to use three conditions in WHERE clause of mysql query?

I want to know if there is any other way of doing it or if I have to forget this idea?


There's nothing wrong with what you're attempting to do, it's just that you haven't quoted the PHP variable

Make sure you're escaping/sanitizing your input. Also use prepared statements if possible

SELECT * FROM posts WHERE userID = $userID AND postBy = '{$postBy}' AND postType = 'unread'


You should really use parameters, but other than that you will need to enclose the text variables in single quotes.

SELECT * FROM posts WHERE userID = $userID AND postBy = '$postBy' AND postType = 'unread'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜