I can not figure out what is wrong with this syntax:
$categorynameresult='SELECT DISTINCT cat_name FROM categories WHERE company = '$companyName' AND cid IN(\''.$categoryids.'\')';
I keep getting this error message:
Parse error: syntax error, unexpected T_VARIABLE in …
I know that $companyName and $categoryids have the values that I need, but there seems to be something wrong with the syntax Could sombody please help me? Thanks
You’re closing the string prematurely with the single quotes around
'$companyName', which is why PHP is giving you a parse error.You could fix this by escaping those quotes (like you’re doing with
$companyids), but variables aren’t interpolated in single quoted strings anyways. Rather than simply escaping the single quotes, you need to use double quotes around the whole string:This assumes that
$categoryidsis a comma-separated list of numeric IDs.