2012-10-26 59 views
0

使用Facebook PHP SDK。我在兩個不同的文件中具有相同的.php標記,在一個工作中,但在另一個文件中,它不返回任何內容。任何想法?我在兩個文件中都包含相同的config.php文件。mysql_fetch_array和Facebook API

include("config.php"); 
include("fbconnect.php"); 

if (!isset($_SESSION['user'])) 
{ 
    $valor_voto = mysql_query("select voto from $mes_id where email=$email"); 
    $row = mysql_fetch_array($valor_voto); 
    $valor = $row['voto']; 

    if ($valor == 1) 
    { 
     echo '<img class="icon" src="/images/greencheck.png">'; 
    } 
    else 
    { 
     echo '<img class="icon" src="/images/check.png">'; 
    } 
} 
else 
{ 
    echo '<img class="icon" src="/images/check.png">'; 
} 

看來,我認爲$email就是失敗,因爲如果我輸入電子郵件手動它將返回任何2個spectated值。

謝謝你的時間。

$email來自fbconnect.php

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

     //Connecting to the database. You would need to make the required changes in the common.php file 
     //In the common.php file you would need to add your Hostname, username, password and database name! 
     mysqlc(); 

     $name  = GetSQLValueString($user_profile['name'], "text"); 
     $email = GetSQLValueString($user_profile['email'], "text"); 
     $gender = GetSQLValueString($user_profile['gender'], "text"); 
     $bio  = GetSQLValueString($user_profile['bio'], "text"); 
     $hometown = GetSQLValueString($user_hometown['hometown'], "text"); 
     $query = sprintf("SELECT * FROM newmember WHERE email = %s", $email); 
     $res  = mysql_query($query) or die('Query failed: ' . mysql_error() . "<br/>\n$sql"); 

     if (mysql_num_rows($res) == 0) 
     { 
      $iquery = sprintf("INSERT INTO newmember values('',%s,%s,%s,%s,'yes',%s)", $name, $email, $gender, $bio, $hometown); 
      $ires = mysql_query($iquery) or die('Query failed: ' . mysql_error() . "<br/>\n$sql"); 

      $_SESSION['user'] = $user_profile['email']; 
      $_SESSION['id'] = $user_profile['id']; 

     } 
     else 
     { 
      $row = mysql_fetch_array($res); 
      $_SESSION['user'] = $row['email']; 
      $_SESSION['id'] = $user_profile['id']; 
     } 
    } 
    catch (FacebookApiException $e) 
    { 
     error_log($e); 
     $user = NULL; 
    } 
} 
+0

$ email從哪裏來? – Maerlyn

+0

請注意,'mysql_xx()'函數被認爲已經過時,並且被PHP棄用。所有這些函數的php手冊頁面都包含一個大的紅色框,表示不使用它們,並切換到'mysqli_xx()'函數或PDO庫。如果可能,我強烈建議進行此更改。 – Spudley

+0

@Maerlyn我添加了$ email的源代碼。 Thx的時候,我正在考慮php手冊中提出的新方法。 –

回答

0

解決了,我不得不條件

if(!isset($_SESSION['user'])) 

,但我不會放棄的條件

if(isset($_SESSION['user'])) 

,所以我不能夠以檢索任何信息。

謝謝你的時間。

1

我假設的電子郵件列是一個字符串,所以你需要把值引號。您還應該轉義它以防止來自Facebook的SQL注入攻擊。

$valor_voto=mysql_query("select voto from $mes_id where email='".mysql_real_escape_string($email)."'"); 

這將是更好的使用庫MySQLi或PDO,而不是過時的mysql擴展,然後你可以使用一個事先準備好的聲明,而不是替換操作和逃避。