【发布时间】:2016-09-19 17:37:12
【问题描述】:
我尝试从 javascript 函数中启动参数,但是当我有空格时,引号似乎有问题。
这是Mozilla的错误
SyntaxError: 未终止的字符串文字
这是我的代码
$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' 这样的正则表达式替换空格,但它是一样的。
【问题讨论】:
-
似乎错误在这里
onclick="lancement('script/php/postgres_query.php',0,'DELETE",没有关闭)还有为什么同一个锚标签上有两个id -
如果我写
onclick=lancement(''script\\\php\\\postgres_query.php'',0,''DELETEFROMtableWHEREid=2'');,Mozilla 的代码返回是好的:onclick="lancement('script/php/postgres_query.php',0,''DELETEFROMtableWHEREid=2"还有,我在 Id 和一个类在 balise<a> -
另外,值得注意的是代码极易受到 SQL 注入攻击。
-
是的,我知道,但它是一个内部工具 ;-)
-
我不认为这是一个很好的借口,但我只是指出了这一点。无论如何,在 PHP 中你正在做
onclick=lancement(...),但如果你有一个带有空格的属性值,那么你需要将整个东西用引号引起来,所以你需要生成onclick="lancement(...)"(或单引号中的等价物)。浏览器向您显示的是它对节点最有可能的表示,而不是实际的 HTML。格式错误的 HTML 仍然可以生成 a 节点(浏览器对错误输入的容忍度很高),但这并不意味着它会起作用。
标签: javascript php