SyntaxError:只有空格的未终止字符串字面值


SyntaxError: unterminated string literal with whitespace only

我尝试从javascript函数中启动参数,但当我有空白时,它似乎是引号的问题。

这是Mozilla

的错误

SyntaxError: unterminated string literal

这是我的代码
$requete = pg_query($dbconnect,"SELECT '<table id=''id1''><col width=''30%''/><col width=''20%''/><col width=''30%''/><col width=''20%''/><tr></tr><tr><td id=''fiche'' colspan=4>Caract</td></tr><tr><td>Stat</td><td>'||coalesce(stat,'')||'</td><td>Service1</td><td>'||coalesce(serv,'')||'</td></tr><tr><td>Date1</td><td>'||coalesce((substring(CAST(date1 AS character varying) from 9 for 2)||'/'||substring(CAST(date1 AS character varying) from 6 for 2)||'/'||substring(CAST(date1 AS character varying) from 1 for 4)),'')||'</td><td>Heure fin</td><td>'||coalesce(heure_fin,'')||'</td></tr><tr><td>Heure début</td><td>'||coalesce(heure_debut,'')||'</td><td>Durée</td><td>'||coalesce(duree::varchar,'')||'</td></tr><tr><td colspan=2><a onclick=document.getElementById(''affichage_popup'').style.display=''none''; class=''bouton'' id=''retour''>Retour</a></td><td colspan=2><a onclick=lancement(''script'''php'''postgres_query.php'',0,''DELETE FROM table WHERE id=2''); class=''bouton'' id=''supprimer''>Supprimer la fiche</a></td></tr></table>' AS fiche FROM table")

如果我用Mozilla分析返回的代码,我得到这个

<a id="test')" where="" intervention="" from="" onclick="lancement('script/php/postgres_query.php',0,'DELETE" id="supprimer" class="bouton">Supprimer la fiche</a>

我尝试用像'/s'这样的正则表达式替换空白,但它是一样的。

为什么不使用pg_escape_string?http://php.net/manual/en/function.pg-escape-string.php

$requete = pg_query($dbconnect,"SELECT '".pg_escape_string("<table ... </table>")."' AS fiche FROM table");

但是如果我看到正确的…你是在开玩笑吧,你在HTML中使用SQL语句…所以每个人都可以改变你的陈述,黑进你的数据库…你听说过SQL注入吗