-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
  • 146,994
  • 96
  • 417
  • 335
Diego_sf93
  • 193
  • 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
  • 146,994
  • 96
  • 417
  • 335
castis
  • 8,154
  • 4
  • 41
  • 63
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
  • 97,268
  • 26
  • 150
  • 164