未添加SQL值

时间:2014-05-16 04:32:57

标签: php mysql instagram

我尝试使用此API在我的网站上进行测试和游戏。 没有任何SQL值存储到表中但是我仍然登录并且能够看到我从IG Api收到的数据

这是成功页面,它接收来自ig的信息以放入表格

<?php
require 'db.php';
require 'instagram.class.php';
require 'instagram.config.php';

// Receive OAuth code parameter
$code = $_GET['code'];



// Check whether the user has granted access
if (true === isset($code)) {

// Receive OAuth token object
$data = $instagram->getOAuthToken($code);
  // Take a look at the API response

if(empty($data->user->username))
{
header('Location: index.php');

}
else
{
session_start();
$_SESSION['userdetails']=$data;
$user=$data->user->username;
$fullname=$data->user->full_name;
$bio=$data->user->bio;
$website=$data->user->website;
$id=$data->user->id;
$token=$data->access_token;

$id=mysql_query("select instagram_id from instagram_users where instagram_id='$id'");

if(mysql_num_rows($id) = 0)
{   
mysql_query("insert into instagram_users(username,Name,Bio,Website,instagram_id,instagram_access_token) values('$user','$fullname','$bio','$website','$id','$token')");
}

header('Location: home.php');
}
} 
else 
{
// Check whether an error occurred
if (true === isset($_GET['error'])) 
{
echo 'An error occurred: '.$_GET['error_description'];
}

}

?>

但是......如果我将数据更改为

mysql_query("insert into instagram_users(username,Name,Bio,Website,instagram_id,instagram_access_token) values('foo','bar','foo','bar.com','0','foo')");

然后它会正常工作。

回到我的mysql_num_rows给了我几乎所有与var dump BESIDES资源numer 6相同的信息?无论那是什么似乎都错了

    insert into instagram_users(username,Name,Bio,Website,instagram_id,instagram_access_token) values('myigusername','my name was here','hey this is where a bio would go','tumblr.com/foobar','Resource id #6','49749frgrgr5tt55558a64r435454t5tfrgefdg') –

1 个答案:

答案 0 :(得分:2)

if(mysql_num_rows($id) = 0)

应该是

if(mysql_num_rows($id) == 0)