开发者

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

开发者 https://www.devze.com 2023-03-09 10:14 出处:网络
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 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

精彩评论

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