函数返回空数据

时间:2011-12-05 14:04:15

标签: php mysql

我使用此函数检查记录是否存在于我的数据库中并采取相应措施。当数据不匹配时,第二部分会出现一些错误:它应该插入一条新记录,但它不会插入新数据,而是返回空数据。我哪里错了?

 class User {

function checkUser($uid, $oauth_provider, $username,$email,$twitter_otoken,$twitter_otoken_secret) 
{

     // Define database connection constants
define('DB_HOST', 'localhost');
define('DB_USER', '*********');
define('DB_PASSWORD', '********');
define('DB_NAME', '******');
    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

    $query ="SELECT * FROM si_table WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'";
    $data=mysqli_query($dbc,$query);
    $result = mysqli_fetch_array($data);
    if (!empty($result)) {

        # User is already present
    } else {

        #user not present. Insert a new Record

     $query2 ="INSERT INTO si_table (oauth_provider, oauth_uid, user_name,email_id,twitter_oauth_token,twitter_oauth_token_secret) VALUES ('$oauth_provider',$uid,'$username','$email')";
        mysqli_query($dbc,$query2);
        $query1 ="SELECT * FROM si_table WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'";
        $data1=mysqli_query($dbc,$query1);
        $row = mysqli_fetch_array($data1);

        return $row;

    }
    return $result;
}



}

1 个答案:

答案 0 :(得分:2)

插入查询中有错误:您只为6个字段提供了4个值。

mysqli_query($dbc, $query2);

的返回值进行一些错误检查