Danny620 Posted January 1, 2010 Share Posted January 1, 2010 <?php //require_once ('facebook/client/facebook.php'); require_once ('settings/mysqli.php'); $appapikey = 'xxxxxxxxxxxxxxxxx'; $appsecret = 'xxxxxxxxxxxxxxx'; //$facebook = new Facebook($appapikey, $appsecret); $fb_user = '2332'; //$facebook->require_login(); class existences { function new_user($fb_user) { $q = "SELECT uid FROM members WHERE uid='$fb_user'"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) == 0) { $q = "INSERT INTO members (uid) VALUES ('$fb_user')"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK return true; }else{ return false; } } } } $new_user = new existences(); $new_user->new_user($fb_user); ?> errors give Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\settings.php on line 18 Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\settings.php on line 20 Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\settings.php on line 23 Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\settings.php on line 23 Notice: Query: INSERT INTO members (uid) VALUES ('2332') MySQL Error: in C:\xampp\htdocs\settings.php on line 23 Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\settings.php on line 25 Quote Link to comment https://forums.phpfreaks.com/topic/186854-cant-find-anything-wrong-with-it-but-it-still-throws-errors/ Share on other sites More sharing options...
sasa Posted January 1, 2010 Share Posted January 1, 2010 you didn't connect to database you error is in 'mysqli.php' Quote Link to comment https://forums.phpfreaks.com/topic/186854-cant-find-anything-wrong-with-it-but-it-still-throws-errors/#findComment-986772 Share on other sites More sharing options...
Danny620 Posted January 1, 2010 Author Share Posted January 1, 2010 still not working but i have included the mysqli file <?php //require_once ('facebook/client/facebook.php'); DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'x'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'web160-fb-app'); // Make the connection: $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (!$dbc) { trigger_error ('Could not connect to MySQL: ' . mysqli_connect_error() ); } $appapikey = '821407345eebe4a9eeddf0c57999e47a'; $appsecret = '6524a8d5c174530ab7a57b5bf3884e9e'; //$facebook = new Facebook($appapikey, $appsecret); $fb_user = '2332'; //$facebook->require_login(); class existences { function new_user($fb_user) { $q = "SELECT uid FROM members WHERE uid='$fb_user'"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) == 0) { $q = "INSERT INTO members (uid) VALUES ('$fb_user')"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK return true; }else{ return false; } } } } $new_user = new existences(); $new_user->new_user($fb_user); ?> Quote Link to comment https://forums.phpfreaks.com/topic/186854-cant-find-anything-wrong-with-it-but-it-still-throws-errors/#findComment-986784 Share on other sites More sharing options...
PFMaBiSmAd Posted January 1, 2010 Share Posted January 1, 2010 Variable scope in classes and class methods works exactly the same way as variable scope in functions. Your $dbc variable does not exist inside your class or your class functions unless you pass it in and make it available in the correct scope. I recommend passing $dbc into your class when you create the instance of your class - $new_user = new existences($dbc); Then have your clsss constructor save it into a class variable - private $dbc; function __construct($dbc) { $this->dbc = $dbc; } Then reference it inside of your class methods using $this->dbc syntax. Quote Link to comment https://forums.phpfreaks.com/topic/186854-cant-find-anything-wrong-with-it-but-it-still-throws-errors/#findComment-986797 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.