Jump to content

cant find anything wrong with it but it still throws errors


Danny620

Recommended Posts

<?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

 

 

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.