如何将facebook电子邮件字段插入mysql服务器数据库?

时间:2013-03-04 05:20:34

标签: php mysql facebook facebook-apps

下面是我将数据插入mysql服务器的代码。每当我尝试添加一个电子邮件字段时,它就会停止工作,即它不再保存数据。

if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$fbuid = $facebook->getUser();
 $user_profile = $facebook->api('/me');


   } catch (FacebookApiException $e) {
   error_log($e);
   $user = null;
   }
     }else{
   header('Location: index.html');

    }
      $query = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook' AND     oauth_uid = ". $user['id']);  
      $result = mysql_fetch_array($query);  

    if(empty($result)){ 
      $query = mysql_query("INSERT INTO users (oauth_provider, oauth_uid, username)         VALUES ('facebook', {$user_profile['id']}, '{$user_profile['name']},{$user_profile['education']} ')");  
       $query = msyql_query("SELECT * FROM users WHERE id = " . mysql_insert_id());  
      $result = mysql_fetch_array($query);  
       }  



   // Login or logout url will be needed depending on current user state.
    if ($user) {
     $paramsout = array('next'=>'http://www.mywebsite.com/test/logout.php');
     $logoutUrl = $facebook->getLogoutUrl($paramsout);
     }


     ?>

修改后的代码,包含电子邮件字段

if(empty($result)){ 
  $query = mysql_query("INSERT INTO users (oauth_provider, oauth_uid, username)         VALUES ('facebook', {$user_profile['id']}, '{$user_profile['name']},{$user_profile['education']} ')");  
   $query = msyql_query("SELECT * FROM users WHERE id = " . mysql_insert_id());  
  $result = mysql_fetch_array($query);  
   }  

1 个答案:

答案 0 :(得分:0)

按照以下教程中给出的步骤进行操作。

http://www.skwebdesigner.com/?p=586