某些字符串未通过GET到达PHP

时间:2012-12-11 21:28:47

标签: php javascript

我正在使用一个非常简单的模型应用程序来查询数据库并在地图上显示结果。应用程序将GET httprequest发送到服务器,该服务器返回一个序列化的值数组。 httprequest的基本结构是:

httpRequest.open("GET","handle-query.php?query=" + queryJs)

,另一方面:

$queryPhp = $_GET["query"];

当查询看起来像这样......

["SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Centre'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Kara'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Maritime'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Plateaux'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%region='Savanes'"]

...然后将其正确传递给服务器,并生成响应。但是,当查询看起来像这样......

["SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Sotouboua'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Tchamba'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Tchaoudjo'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Assoli'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Bassar'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Bimah'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Doufelgou'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Keran'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Kozah'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Golfe'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Lacs'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Vo'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Yoto'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Zio'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Amou'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Haho'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Kloto'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Ogou'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Wawa'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Oti'", "SELECT%SUM(commit)%FROM%financialdata%WHERE%prefect='Tone'"]

...然后服务器收到一个空字符串。这两个字符串都是由同一个函数生成的,并且都在我的虚拟服务器(WAMP)上完美运行。如果有人有任何想法,将不胜感激。

(PS阅读后我意识到我应该使用一个更好的消毒等框架,但这只是一个需要在线生活2个小时的演示,最好修复这个小东西比重新开始。它在我的本地主机上完美运行。)

1 个答案:

答案 0 :(得分:2)

要实际回答您的问题,您要发送一个get参数query(handle-query.php?query =),然后将其拉出queryJS(queryJs)。

$_GET['query'] // instead of $_GET['queryJs']

应该这样做。

(并且正如大家所指出的那样,不要以明文或其他方式发送SQL,除非你打算不实际执行SQL,并且你只是想宣传你的数据库结构,也许它就是那么漂亮。)