使用SQL LIKE子句

I would like to concatenate a variable into my LIKE clause. I believe I am doing it wrong. What can I do?

$query2= "SELECT user_id FROM interests WHERE interest LIKE     
'%'".$interest."'%'";

The positioning of quotes are wrong. Check the single quotes around the % symbols.

$query2= "SELECT user_id FROM interests WHERE interest LIKE '%".$interest."%'";

What you had before was '%' $interest '%' instead of '% $interest %' which is what you'd want.

This would be a correct way to concatenate a variable into a string:

$query2 = "SELECT user_id FROM interests WHERE interest LIKE '%" . $interest. "%'";

You had extra single quotes after LIKE.

However, you should used prepared statements using mysqli_ or PDO.

remove the single quotes after %.

Remove your extra quotes and don't forget to escape your external input (or use prepared statements).

$query2= "SELECT user_id FROM interests WHERE interest LIKE '%".
         mysqli_real_escape_string($interest)."%'";