0

所以我让FB连接使用PHPSDK工作。对于初学者,我这样做是为了当用户注册时,它会自动创建他们的个人资料(个人资料图片、全名、年龄、性别、工作/雇主、电子邮件等)

所以效果很好,一键创建配置文件。

但是,我正在尝试这样做,因此当用户单击“使用 Facebook 注册”按钮时,它还会将用户数据与后端一起存储在后台。我是否必须通过提交表单按钮来完成它并将下面的所有变量定义为 $_POST 来存储它?(我正在使用 PDO/MySQL 来执行此操作,例如,请参见下文

我尝试了以下但它不起作用。

$user = "xxxx";
$pwd = "xxxx";

$odb = new PDO("mysql:host=localhost;dbname=xxxx;", $user, $pwd);

$q = "INSERT INTO users(u_fullname, age, u_location, u_gender, u_bday, u_employer, u_job) VALUES(:u_fullname, :age, :u_location, :u_firstname, :u_gender, :u_bday, :u_employer, :u_job)";
$query = $odb->prepare($q);
$results = $query->execute(array(":u_fullname" => $u_fullname, ":age" => $age, ":u_location" => $u_location, ":u_gender" => $u_gender, ":u_bday" => $u_bday, ":u_employer" => $u_employer, ":u_job" => $u_job));

这是个人资料设置

<? $fbuid = $user_profile['id'];
$u_employer = $user_profile['work'][0]['employer']['name'];
$u_job = $user_profile['work'][0]['position']['name'];
$u_firstname = $user_profile['first_name'];
$u_fullname = $user_profile['name'];
$u_location = $user_profile['location']['name'];
$u_gender = ucfirst($user_profile['gender']);
$u_bday = $user_profile['birthday'];
//explode the date to get month, day and year
$u_bday = explode("/", $u_bday);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $u_bday[0], $u_bday[1], $u_bday[2]))) > date("md") ? ((date("Y")-$u_bday[2])-1):(date("Y")-$u_bday[2]));?>

任何帮助将不胜感激!

4

0 回答 0