1

好吧,我要做一个 Facebook MySQL 和 PHP 项目,但我收到一个错误,我不知道这是什么,有一个页面和一个输入(文本)用户输入和 facebook 的 id 帖子,用户点击提交通过 jQuery 将数据发送到 like_object.php 的按钮,其代码为:

<?php
    require 'facebooksdk/facebook.php';
    $id = trim($_POST ['postid']);

    if(empty($id)){
        die("forbidden");
    } else {
       $token  = $_GET["accesstoken"];

       include('config.php');

       //Create facebook application instance.
       $facebook = new Facebook(array(
           'appId'  => $fb_app_id,
           'secret' => $fb_secret
       ));

       $output = '';

       //get users and try liking
       $result = mysql_query("
          SELECT
              *
          FROM
              W3 
       ");

      if($result){
          while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
              $m = $row['access_token'];
              $facebook->setAccessToken ($m);

              try {
                  $facebook->api("/$id/likes", 'POST');
                  $msg1 = "<div class='alert alert-info'><strong>Success</strong></div>";
              } catch (FacebookApiException $e) {
                  $output .= "<p>'". $row['name'] . "' failed to like.</p>";
                  $msg2 = "<font color='red'>Failed to Like!</font>";
              }
          }
      }
      mysql_close($result,$connection);
  }
?>

我检查了错误日志(facebook SDK 生成它)

[16-Jul-2013 15:25:29] PHP Warning:  Wrong parameter count for mysql_close() in /home/like_object.php on line 43

[16-Jul-2013 15:27:24] PHP Parse error:  syntax error, unexpected T_VARIABLE in /home/like_object.php on line 33

那么我的php哪里出了问题?

4

3 回答 3

1
trim($_POST ['postid']); 

需要是

trim($_POST['postid']); 

$msg1 = "
       <div class='alert alert-info'><strong>Success</strong></div>
";

需要是

$msg1 = "<div class='alert alert-info'><strong>Success</strong></div>";

mysql_close($result,$connection);

需要是

mysql_close($connection);

另外,mysql is deprecated. 请查看mysqli

$facebook->setAccessToken ($m);

需要是

$facebook->setAccessToken($m);
于 2013-07-16T20:20:37.630 回答
0

一个可能的解决方案是改变:

$id = trim($_POST ['postid']);

到:

$id = trim($_POST['postid']);
于 2013-07-16T20:18:38.567 回答
0

尝试使用最新版本的Facebook SDK 可能会有所帮助

于 2013-07-17T06:07:48.790 回答