我在这里遇到一些奇怪的行为。 我正在使用下面的代码来引用Facebook的API。PHP字符串错误
$query = "SELECT msg, user_id, comment_time FROM comments WHERE aid = '$aid' ORDER BY comment_time DESC";
$result = mysql_query($query) or die("ERROR: $query.".mysql_error());
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_object($result)){
$uidval = $row->user_id;
$posterInfo = $facebook->api_client->users_getInfo($uidval, array('name', 'pic_square_with_logo', 'profile_url'));
$nameuser = $posterInfo[0]['name']; //this is line 50
$pic = $posterInfo[0]['pic_square_with_logo'];
$profile_url = $posterInfo[0]['profile_url'];
echo '<img src="'.$pic.'" />';
echo '<a href="'.$profile_url.'">'.$nameuser.'</a>';
echo '<br>';
echo $row->comment_time;
echo '<br>';
echo $row->msg;
}
}
它给了我这个错误:
Fatal error: Cannot use string offset as an array in /home/amitver/public_html/roadies/comments.php on line 50
但令人惊讶的我正在成功地利用完全相同的代码在我的页面的顶部。为什么这个奇怪的行为。这是页面顶部的代码:
//connect to fB
$uid = $user_id;
$userInfo = $facebook->api_client->users_getInfo($user_id, array('name', 'pic_square'));
$nameuser = $userInfo[0]['name'];
$pic = $userInfo[0]['pic_square'];
你说明这行是#50在源? – pix0r 2010-01-13 20:27:37
您应该避免使用字符串连接来构建查询并生成HTML结果。您的代码中可能存在SQL注入漏洞和/或XSS漏洞。 – 2010-01-13 20:33:08