syntax error, unexpected 'if' (T_IF) [closed]

-5

What is the error?

$sql = "SELECT item1, item2, item3 FROM tab_exemplo WHERE" 
if (isset($item3)) {echo 'quartos LIKE :A';}
if (isset($item2) || isset($item1) || isset($item4)){echo 'AND'}
if (isset($item4)){echo 'garagens LIKE :B';}
if (isset($item2) || isset($item1) || isset($item3)){echo 'AND'}
if (isset($item2)){echo 'tipoNegocio LIKE :C';}
if (isset($item3) || isset($item1) || isset($item4)){echo 'AND'}
if (isset($item1)){echo 'tipo LIKE :D';} echo '\"';
    
asked by anonymous 21.08.2016 / 23:51

1 answer

4

Try to better organize your code that will avoid simple bugs like this. Note below how it is easier to read and troubleshoot the code. ; missing when finalizing multiple lines.

Make sure you also interpret the error messages and look in the documentation about them. In programming mistakes happen to the hills. If there is a question you have to ask someone to get slow and tiring.

Often the error appears in one place but is in another. The compiler / interpreter can not understand intent. If it lacks a semicolon that terminates the command, then the error will only appear on the next line when it finds something strange in what it still considers the middle of the command (although you programmer intended it to be a new command). >

Mounting SQL expressions thus can be reckless in terms of security depending on where these variables come from.

In the comment it was mentioned that it would be to concatenate strings . Even if the question posed was the same, it would still have to change a lot. Not only would you have to concatenate the variable $sql instead of using echo , but you also need to review the organization of the text as this would not produce a correct query. I also find it strange how to determine what to concatenate.

    
21.08.2016 / 23:59