2016-09-19 127 views
0

我尝试从javascript函数启动参数,但是当我有一个空格时,它似乎是引用问题。SyntaxError:未终止的字符串文字只有空格

这是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'等正则表达式代替空格,这是同样的事情。

+0

似乎错误在这里'onclick ='lancement('script/php/postgres_query.php',0,'DELETE'',没有关闭')'同样为什么在同一个锚标记上有两个id – brk

+0

如果我写'onclick = lancement(''script \\\ php \\\ postgres_query.php'',0,''DELETEFROMtableWHEREid = 2'');',Mozilla的代码返回很好:'onclick =“lancement(' script/php/postgres_query.php',0,''DELETEFROMtableWHEREid = 2''也是,我已经在Id和一个班级上了'' –

回答

1

为什么你没有使用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语句中使用......所以每个人都可以改变你的statment和黑客您的数据库......你听说过一些SQL Injection

+0

不幸的是,使用这个函数更容易编写代码,非常感谢!但它不是解决方案:(它同样的事情,但事实上,点击按钮我已经这个代码'36970',当我点击爆炸...... –

+0

最后,并在你的帮助下,我选择使用变量而不是使用SQL注入,它更安全,而且更简单!谢谢你的帮助 –