-1

I have this code in PHP:

$_pagi_sql='SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST ('"$criterio"' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()';

I want to put exactly this string in the variable $_pagi_sql:

SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST ('"STH"' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()

However the double quotes are not properly stored in the variable $_pagi_sql

How can it be done?

Eric Leschinski
  • 135,913
  • 89
  • 401
  • 325
Diego_sf93
  • 181
  • 1
  • 1
  • 9

2 Answers2

0

You can enter double quotes by adding slashes before your single quotes.

$_pagi_sql='SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST (\'"$criterio"\' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()';
Eric Leschinski
  • 135,913
  • 89
  • 401
  • 325
castis
  • 8,041
  • 4
  • 41
  • 62
0

Replace the single quotes from right handle side with double quotes:

$_pagi_sql="SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST ('\"$criterio\"' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()";

Or, get rid of the quotes, use heredoc:

$_pagi_sql = <<<SQL
SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST ('"$criterio"' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()
SQL;
Hashem Qolami
  • 93,110
  • 25
  • 145
  • 156