PHP比较运算符==不按要求工作。奇怪的行为

时间:2015-06-10 21:39:45

标签: php mysql pdo oauth twitter-oauth

我尝试在用户成功后更新用户的帐户 通过Twitter(Twitter Oauth)进行身份验证。回调网址为www.xyxy.com/email.php

我希望用户在他/她经过身份验证后更新其个人资料并更改电子邮件ID。 我的`oauth表包含以下列: twitter句柄,access_token,access_secret_key,电子邮件

我的INSERT命令中插入了垃圾邮件列,因为我将更新它 我的email.php页面中的列。我希望用户只有在他没有更新他的情况下才能看到email.php页面 电子邮件ID,否则他应该登陆index.php页面。

为实现这一目标,我使用了SELECT命令并将电子邮件字段存储在变量中。然后 我已经将此变量与垃圾值进行了比较,因此header()函数已经进行了比较 书面。但控制似乎永远不会进入if条件。

email.php

<?php
/**
 * @file
 * User has successfully authenticated with Twitter. Access tokens saved to session and DB.
 */

/* Load required lib files. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
require('mysqlconnection.php');

/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
    header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];


/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);



/* If method is set change API call made. Test is called by default. */
$data = $connection->get('account/verify_credentials');


$screen_name = $data->screen_name;


/*Updating oauth table with user tokens.*/
try {


    // begin the transaction
    $conn->beginTransaction();
    // our SQL statememtns


    $conn->exec("INSERT IGNORE INTO oauth (twitterhandle,access_token, oauth_token_secret, email) 
    VALUES ('".$screen_name."','".$access_token['oauth_token']."','".$access_token['oauth_token_secret']."','inialgarbagevalue@example.com')");


    // commit the transaction
    $conn->commit();
   // echo "New records created successfully";
    }
catch(PDOException $e)
    {
    // roll back the transaction if something failed
    $conn->rollback();
    echo "Error: " . $e->getMessage();
    }

$stmt = $conn->prepare("SELECT email FROM oauth WHERE twitterhandle = :value");
$stmt->execute(array(':value' => $screen_name));

$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$total = count($result);
//print_r($result);
$email = $result;
print_r($email);


//echo gettype($email[0][0]);
//echo $email[0][0];

$fetchedresult = $email[0]['email'];
$garbagevalue = "inialgarbagevalue@example.com";

//echo $fetchedresult;

   更新1:    输出echo $fetchedresult;

inialgarbagevalue@example.com     

   输出print_r($email);

数组([0] =&gt;数组([email] =&gt; inialgarbagevalue@example.com))     

 //echo $garbagevalue;

if($fetchedresult == $garbagevalue)
{
echo"if part";

 //take email id from user via a form.
/*
$sql1 = UPDATE oauth   
   SET `emailid` = :newemailid
 WHERE `twitterhandle` = :screen_name
 */
 header('Location: http://www.xyxyxy.com/email.php'); 
}

if($fetchedresult != $garbagevalue)
{
echo "Else part executed";
//header('Location: http://www.xyxyxy.com/index.php'); 
}

$conn = null;

?>
<!DOCTYPE html>
<html>
<head>
    <title>XYXY - Index</title>
    <link rel="stylesheet" href="css/style.css">
</head>


<body>

<center>
    <div id="content">

     <h3>Account Update</h3>
     <form id="changemail" action="" method="post">
        <p>
          <label for="emailid">Update your account Email ID:</label>
          <input type="text" name="emailid" id="emailid"/>
        </p>


        <p>
          <input type="submit" name="btnUpdate" value="Update" />
        </p>
      </form>

      <td>&nbsp;</td>
<p>
 <?php
    echo "<p align='left'><a href='clearsessions.php' >Sign Out</a></p>";
    ?>
  </p>

        </div>
</center>
</body>
</html>

为什么我对此行为表示欢迎?如何实现所需的方案?

0 个答案:

没有答案
相关问题