【发布时间】:2012-08-27 14:09:51
【问题描述】:
我遇到了这个错误
警告:mysqli_fetch_array() [function.mysqli-fetch-array]:无法获取 /home/fights7/public_html/include/load_more_home_posts.php 中的 mysqli_result在 12
行
想知道我在下面的代码中做错了什么吗?
$articles_data = mysqli_query($mysqli,"SELECT * FROM streamdata WHERE streamitem_id < '$lastID' ORDER BY streamitem_id DESC LIMIT 10") or die(mysql_error());
while($articles_info = mysqli_fetch_array($articles_data)) {
$json = array();
$json['streamitem_id'] = $articles_info['streamitem_id'];
$json['streamitem_content'] = $articles_info['streamitem_content'];
$json['streamitem_timestamp'] = $articles_info['streamitem_timestamp'];
mysqli_free_result($articles_data);
【问题讨论】:
-
希望
$lastID被正确过滤/清理/转义。否则你很容易受到SQL injection attacks -
是的,使用 msqli_real_escape_string($last_id)。为什么人们对这里的 SQL 注入如此着迷?
-
@dave 因为我们看到了很多很多真正糟糕的 PHP 代码,并且遇到了很多甚至从未听说过 SQL 注入的新用户 :( 安全总比抱歉好,所以我们如果我们在发布的代码中没有明确看到转义和过滤,总是指出来。
-
@dave:我的粗略估计是这里大约 90% 以上的 php 发帖者对注入问题一无所知。
-
很好@MichaelBerkowski,也许我会开始在网站周围做同样的事情来帮助别人。