Reputation: 701
define('DB_HOST', 'localhost');
define('DB_USER', '******');
define('DB_PASSWORD', '************');
define('DB_NAME', '***********');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
class User {
function checkUser($uid, $oauth_provider,$username,$email,$twitter_otoken,$twitter_otoken_secret)
{
$query = mysqli_query($dbc,"SELECT * FROM si_table WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'");
$result = mysqli_fetch_array($query);
if (!empty($result)) {
# User is already present
} else {
#user not present. Insert a new Record
$query = mysqli_query($dbc,"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')") ;
$query = mysqli_query($dbc,"SELECT * FROM si_table WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'");
$result = mysqli_fetch_array($query);
return $result;
}
return $result;
}
}
I am getting this error! I don't know why?
mysqli_query() expects parameter 1 to be mysqli, null given in line 14,15,20,21 and 22!
Upvotes: 3
Views: 6630
Reputation: 143051
Add global $dbc;
to the beginning of the checkUser
. The variable is not defined in the function scope.
Upvotes: 7