3
 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!

3

1 Answer 1

7

Add global $dbc; to the beginning of the checkUser. The variable is not defined in the function scope.

Sign up to request clarification or add additional context in comments.

3 Comments

This works..but I had a doubt..if $dbc was declared outside the class,(which by default makes it global) then why aggain make it global? I am sorry, if I am wrong..coz I am newbie..
Yes, it may be worth noting, that I only dealt with immediate problem.
@RobbieDc, this is how php works. Why using php is another question :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.