我使用这个函数来检查记录是否存在于数据库中,并相应地执行。当数据不匹配时,第二部分有一些错误:它应该插入一个新记录,但它不插入新数据,并且返回空数据。我哪里做错了?

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



}

最佳答案

插入查询中有错误:仅为6个字段提供4个值。
mysqli_query($dbc, $query2);的返回值进行一些错误检查

10-05 19:29