意想不到的T_VARIABLE [关闭]

I knew that, this question is a repetition :

 if (($_POST['os'] != "") || ($_POST['cp'] != "") || ($_POST['ser'] != "")) {

                  $var .= "left join (select bug_id,os,cp,service from category_bug_map where category_bug_map.os like '."$_POST['os']".' and category_bug_map.cp like '."$_POST['cp']".' and category_bug_map.service like '."$_POST['ser']".') as category_map on ( category_map.bug_id = bugs.bug_id)";
              }

And it is showing that, on $var, unexpected T_VARIABLE.What is the problem with this?

These pieces: '."$_POST['cp']".' are incorrect. Rewrite like this:

'".$_POST['cp']."' 

Some more info here: http://php.net/manual/en/language.operators.string.php

Why do you post it, if you know it is a repetition?

Your dots in the $var line for $_POST must not be within the string delimiter, but outside.

Furthermore this code is awful, as it exposes sql injection issues: http://de.wikipedia.org/wiki/SQL-Injection

I think your problem is the way you are trying to concatenate the string with $_POST. Instead of '."$_POST['os']".' you have to precede " before .

'".$_POST['os']."'

This is because . (dot) is the concatenation operator and has to come between segments of a string.

Replace this in your code: $var .= "left join (select bug_id,os,cp,service from category_bug_map where category_bug_map.os like '".$_POST['os']."' and category_bug_map.cp like '".$_POST['cp']."' and category_bug_map.service like '."$_POST['ser']".') as category_map on ( category_map.bug_id = bugs.bug_id)";