0

使用 Facebook PHP SDK。我在两个不同的文件中有相同的 .php 标签,在一个文件中它可以工作,但在另一个文件中它什么也不返回。任何的想法?我config.php在两者中都包含相同的文件。

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 个预期值中的任何一个。

谢谢你的时间。

$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;
    }
}
4

2 回答 2

1

我假设电子邮件列是一个字符串,因此您需要将值放在引号中。您还应该转义它以防止来自 Facebook 的 SQL 注入攻击。

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

使用 mysqli 或 PDO 会更好,而不是已弃用的 mysql 扩展,然后您可以使用准备好的语句而不是替换和转义。

于 2012-10-26T19:30:32.533 回答
0

解决了,我有条件

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

但我没有给出条件

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

所以我无法检索任何信息。

谢谢你的时间。

于 2012-10-27T23:32:44.237 回答