syntax error, unexpected T_CONSTANT_ENCAPSED_STRING


I get this error in php when I want to make a query by date someone knows where the error is, I can not find it.

$consulta1+="year(cast(cast(fch as datetime)-1 as date))= " .$anio1 "and month(cast(cast(fch as datetime)-1 as date))= " .$chkBox.$condicion. ") as s"; 

I intend to pass the value of a year by means of a combobox and of the month by means of the value assigned to one or several checkboxes.

asked by Alberto Arenas 05.10.2016 в 18:38

1 answer


There are two errors in that line of code:

  • The concatenation in PHP must be done with the point . but you are assigning with += . You should do .= or the result obtained will be 0 instead of the desired string.
  • You need to add a concatenation after $anio1 and that's what really causes you the error you show.
  • Changing that, it works:

    $consulta1.="year(cast(cast(fch as datetime)-1 as date))= " .$anio1. " and month(cast(cast(fch as datetime)-1 as date))= " .$chkBox.$condicion. ") as s";
    answered by 05.10.2016 / 18:54