Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL query returning rows from every user

Tags:

php

mysql

I have a simple search script to search a database which should return all the rows of data that match the search query that belong to that user, however my query (below) is returning rows from every user. Any idea how to fix this?

SELECT * FROM tablename 
WHERE title LIKE '%" . $q . "%' 
OR text LIKE '%" . $q . "%' 
AND user='$user'

Side Note: This is executed in PHP so the $q is the variable that holds the query.

like image 553
Stephen Cioffi Avatar asked Aug 25 '26 01:08

Stephen Cioffi


1 Answers

Have you tried this?

"SELECT * FROM tablename WHERE (title LIKE '%".$q."%' OR text LIKE '%".$q."%') AND user='$user'"
like image 160
salih0vicX Avatar answered Aug 26 '26 14:08

salih0vicX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!