使用 PHP 将电影标题传递到 MySQL 数据库时,出现以下错误:
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 's Dreams' )' at line 10
这是我的代码:
//Getting a list of all the users friends
$MyFriends=$facebook->api('/me/friends');
//Loop through friends array to identify each friend
$c=0;
while ($c<count($MyFriends['data']))
{
$N=$MyFriends['data'][$c]['name'];
$I=$MyFriends['data'][$c]['id'];
mysql_query("INSERT INTO UserFriends
(
UserFBID,
FriendFBID,
DisplayName
) VALUES
(
'$FBID',
'$I',
'$N'
) ") or die(mysql_error());
//Getting a list of friends each movie likes
$friendId = "/" . $I . "/movies";
$myFriendsMovies=$facebook->api($friendId);
//Loop through to identify each movie
$x=0;
while ($x<count($myFriendsMovies['data']))
{
$r = $myFriendsMovies['data'][$x]['id'];
$s = $myFriendsMovies['data'][$x]['name'];
mysql_query("INSERT INTO LinkedMovies
(
UserFBID,
MovieFBID,
MovieName
) VALUES
(
'$I',
'$r',
'$s'
) ") or die(mysql_error());
$x=$x+1;
}
$c=$c+1;
}
似乎变量 $s 已经拿起了电影“Akira Kurosawa's Dreams”并不断轰炸,出现上述错误。