facebook php sdk将所有' 5保存到mysql数据库字段而不是数据

时间:2013-03-05 03:59:10

标签: php facebook sdk

遵循本教程http://www.skwebdesigner.com/?p=586 下面是我的fbconnect.php代码的摘录。

if($user){
    // Get logout URL
    $logoutUrl = $facebook->getLogoutUrl();
}else{
    // Get login URL
    $loginUrl = $facebook->getLoginUrl(array(
        'scope'         => 'read_stream, publish_stream, email, user_about_me',
        'redirect_uri'  => $site_url,
        ));
}

if($user){

    try{
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
    //Connecting to the database. You would need to make the required changes in the common.php file
    //In the common.php file you would need to add your Hostname, username, password and database name!
    mysqlc();

    $name = GetSQLValueString($user_profile['name'], "text");
    $email = GetSQLValueString($user_profile['email'], "text");
    $gender = GetSQLValueString($user_profile['gender'], "text");
    $bio = GetSQLValueString($user_profile['bio'], "text");
    $query = sprintf("SELECT * FROM newmember WHERE email = %s",$email);
    $res = mysql_query($query) or die('Query failed: ' . mysql_error() . "<br />\n$sql");
    if(mysql_num_rows($res) == 0)
    {
        $iquery = sprintf("INSERT INTO newmember values('',%s,%s,%s,%s,'yes')",$name,$email,$gender,$bio);
        $ires = mysql_query($iquery) or die('Query failed: ' . mysql_error() . "<br />\n$sql");
        $_SESSION['user'] = $user_profile['email'];
        $_SESSION['id'] = $user_profile['id'];
    }
    else
    {
        $row = mysql_fetch_array($res);
        $_SESSION['user'] = $row['email'];
        $_SESSION['id'] = $user_profile['id'];
    }
    }catch(FacebookApiException $e){
            error_log($e);
            $user = NULL;
        }

}
}
?>

正确连接到数据库,但将每个字段的Facebook信息保存为5。另请注意,今天早些时候它为每个领域节省了1个。

我尝试了什么

将$ user更改为$ user_profile

感谢

1 个答案:

答案 0 :(得分:0)

非常确定插件的'sprintf'需要在%s周围引用。您可以通过打印$ iquery来检查。