将facebook app用户详细信息插入数据库

时间:2010-05-12 18:58:05

标签: php mysql facebook

我正在尝试将授权应用程序的用户详细信息插入到数据库中,但似乎没有发生任何事情。数据为空,没有插入记录。代码有什么问题吗?

function insertUser($user_id,$sk,$conn)
{

    //$info = $facebook->api_client->users_getInfo($user_id, 'first_name, last_name', 'name', 'sex');
    $info = $facebook->api_client->fql_query("SELECT uid, first_name, last_name, name, sex FROM user WHERE uid = $user_id");

    for ($i=0; $i < count($info); $i++) {
    $record = $info[$i]; 
    $first_name=$record['first_name'];
    $last_name=$record['last_name'];
    $full_name=$record['name'];
    $gender=$record['sex'];

    }

    $data= mysql_query("select uid from users where uid='{$user_id}'",$conn);
    if(mysql_num_rows($data)==0)
    {
        $sql = "INSERT INTO users (uid,sessionkey, active, fname, lname, full_name, gender) VALUES('{$user_id}','{$sk}','1', '{$first_name}', '{$last_name}', '{$full_name}', '{$gender}')";
        mysql_query($sql,$conn);
        return true;
    }
    return false;
}

1 个答案:

答案 0 :(得分:0)

手动调用安装代码,而不是将其留在facebook上ping网址。