Data of some Facebook users not pasting mysql into the database

I have a strange but definitely serious problem with getting data from some Facebook users who authorize my application and use it (usually by the way).

Currently, the application uses up to 3000 users, but only 600 are displayed in the user table. How is this possible? I can’t find the connection between old and new users - for some it works flawlessly, for others it just does not work at all.

Here's the complete, but for security reasons censorship code:

<?php require 'facebook.php'; include 'config.php'; session_start(); $app_id = 'id'; $app_secret = 'secret'; $app_namespace = 'namespace'; $app_url = 'https://apps.facebook.com/' . $app_namespace . '/'; $scope = 'email,publish_actions'; 

// Initiate the SDK for Facebook

  $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true )); 

// Get current user

  $user = $facebook->getUser(); 

// If the user has not installed the application, redirect it to the Auth dialog

  if (!$user) { $loginUrl = $facebook->getLoginUrl(array( 'scope' => $scope, 'redirect_uri' => $app_url, )); print('<script> top.location.href=\'' . $loginUrl . '\'</script>'); } else if ($user) { try { 

// Continue to understand that we have an authenticated registered user.

  $fbuid = $facebook->getUser(); $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; } } else{ header('Location: index.php'); } $queryUserExists = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook'AND oauth_uid = " . $user_profile['id']); $num=mysql_numrows($queryUserExists); 

// If not, add it to the database

  if ($num == 0) { $query = mysql_query("INSERT INTO users (oauth_uid, oauth_provider, username, first_name, last_name, email, pic_square ,login_date , dailytokens) VALUES ({$user_profile['id']}, 'facebook', '{$user_profile['name']}', '{$user_profile['first_name']}','{$user_profile['last_name']}','{$user_profile['email']}', '".$photolink."',CURDATE(),1)"); $query = mysql_query("SELECT * FROM users WHERE oauth_uid = " . mysql_insert_id()); $result = mysql_fetch_array($query); } else { $DateLastLogin=mysql_result($queryUserExists,0,"login_date"); $myDate = date('Ym-d'); $CompLastDate = strtotime($DateLastLogin); $CompMyDate = strtotime($myDate); if($CompLastDate < $CompMyDate){ $updateDailyToken = "Update users set login_date=CURDATE(), dailytokens = dailytokens + 1 where oauth_uid =" . $user_profile['id']; $updateToken= mysql_query($updateDailyToken) or die(mysql_error()); } } $query = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook' AND oauth_uid = " . $user_profile['id']); $_SESSION['userid']=$user_profile['id']; 

// Logging in or logging out will be necessary depending on the current state of the user.

  if ($user) { $paramsout = array('next'=>'http://facebook.com'); $logoutUrl = $facebook->getLogoutUrl($paramsout); } ?> 
+4
source share
2 answers

The problem is with the type of object in the database. Some facebook users have an incremented big id: 0098788563000236, for example, so using BIGINT instead of INT solved it.

+1
source

here is your problem

 $query = mysql_query("INSERT INTO users (oauth_uid, oauth_provider, username, first_name, last_name, email, pic_square ,login_date , dailytokens) VALUES ({$user_profile['id']}, 'facebook', '{$user_profile['name']}', '{$user_profile['first_name']}','{$user_profile['last_name']}','{$user_profile['email']}', '".$photolink."',CURDATE(),1)"); 

he should be

 $query = mysql_query("INSERT INTO users (oauth_uid, oauth_provider, username, first_name, last_name, email, pic_square ,login_date , dailytokens) VALUES ('{$user_profile['id']}', 'facebook', '{$user_profile['name']}', '{$user_profile['first_name']}','{$user_profile['last_name']}','{$user_profile['email']}', '{$photolink}',CURDATE(),1)"); 
+1
source

Source: https://habr.com/ru/post/1434392/


All Articles