0

FBでデータを収集し、DBに送信しています。アプリが実行されており、データがDBに挿入されていることを確認できますが、解決方法がわからないというエラーが発生します。私はこれについて研究し、結果なしでいくつかの解決策を試しました。エラーが何であるかを確認するためにコード行を追加しました。それを解決するために私を導いてください。ありがとう

エラー:

 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
 Unknown column 'id' in 'where clause'

エラーは私にこの行を示しています:

 $result = mysql_fetch_array($query) or die ( mysql_error () );  

これは私のコードです:

<?php
define('db_user','xxx');
define('db_password','xxx');
define('db_host','xxx.xxx.com');
define('db_name','xxx');

// Connect to MySQL
 $dbc = @mysql_connect (db_host, db_user, db_password) OR die ('Could not connect to      MySQL: ' . mysql_error() );
// Select the correct database
mysql_select_db (db_name) OR die ('Could not select the database: ' . mysql_error() );
mysql_set_charset('utf8',$dbc);

require 'src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId'  => 'xxxx',
'secret' => 'xxxx',
  'cookie' => true));


// Get User ID
 $user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

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.php');

    }

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


    if(empty($result)){ 
      $query = mysql_query("INSERT INTO users (oauth_provider, oauth_uid, username, first_name, last_name, birthday, email, pic_square ) VALUES    ('facebook', {$user_profile['id']}, '{$user_profile['name']}', '{$user_profile['first_name']}','{$user_profile['last_name']}','{$user_profile['birthday']}','{$user_profile['email']}', '{$user_profile['pic_square']}')");  
  $query = mysql_query("SELECT * FROM users WHERE id = " . mysql_insert_id());  
  $result = mysql_fetch_array($query) or die ( mysql_error () );  


 }  


   // 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);
     }
     ?>
     <html><body>welcome</body></html>
4

2 に答える 2

0

'where句'の不明な列'id'

実際にidという名前の列がありますか?これが実際に列に名前を付けたものであることを確認してください。

idという名前の列がない場合は、次を使用して追加できます。

ALTER TABLE `users` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT FIRST

AUTO_INCREMENTを使用すると、列'id'によって、データベースに挿入する各行に新しいID番号が自動的に割り当てられ、ここで示したコードが機能します。

于 2012-08-19T16:05:26.493 に答える
0

失敗するクエリは次のとおりです。

$query = mysql_query("SELECT * FROM users WHERE id = " . mysql_insert_id()); 

エラーメッセージに示されているように、テーブルには。usersというフィールドが含まれていませんid

データベースのフィールド名を確認し、クエリを更新すると、機能するはずです。

于 2012-08-19T15:58:54.250 に答える