2016-09-19 35 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注入,它更安全,而且更簡單!謝謝你的幫助 –