Help me with $db plugin error
#1
This is my partial plugin code:

I get this error: Call to a member function simple_select() on a non-object  

$ids = $_GET['case']; 
$emailr = $db->real_escape_string($_GET['email']);
//...


function readerthread_thread($emailr, $db)

{
 global $db, $mybb; 
    $query = $db->simple_select("SELECT * FROM ".TABLE_PREFIX."users WHERE email='$emailr'");
		while($row = $db->fetch_array($query));
			{
		echo $row['postnum'];
		}			
}

switch($ids)

{
	case thread: readerthread_thread($emailr, $db); break;
}
Reply
#2
You have to declare or globalize vars before use it.

You call on email var to a globalized var db and then you call it that was the error only globalize at the begining once and then its done.

Its like you want to make a pay and before make it put all contents not after.
The only infinite thing is the universe and human stupidity, but the universe is not for sure

Plugins 1.6.x

Plugins 1.8.x

Reply
#3
(2015-03-22, 03:10 PM)Dark Neo Wrote: You have to declare or globalize vars before use it.

You call on email var to a globalized var db and then you call it that was the error only globalize at the begining once and then its done.

Its like you want to make a pay and before make it put all contents not after.

You can write an example?
i can't understand
Reply
#4
Did you include global.php in your file?
Reply
#5
(2015-03-22, 04:05 PM)Destroy666 Wrote: Did you include global.php in your file?

Yes, i get always these errors:
Call to a member function simple_select() on a non-object 
Call to a member function real_escape_string() on a non-object
Reply
#6
You can't use $db as an argument for your function. Remove all instances of it as an argument for a function. Also you should be using $db->escape_string not $db->real_escape_string.
Reply
#7
Read plugins documentation because you are using bad code args.

simple select its a mybb standard call where receive arguments by default you have tu use db query to use like that.

Call to db at the first time and or add vars with your code and use a php functions to make works.

I did not know if real escape exist i use everytime only db escape string, taken from mybb default and goes fine im sure you do not read the doc guidance to start on make plugins i recomend you to read that first at all or tell us what you wanna do on your plugin and its more easy to make a code than repair yours.
The only infinite thing is the universe and human stupidity, but the universe is not for sure

Plugins 1.6.x

Plugins 1.8.x

Reply
#8
If you're getting an error of calling a function on a non-object then whatever you're trying to escape isn't an object...exactly like the error says. Do you understand how $_GET and $_POST work? If you don't have "[email protected]" in your URL then $_GET['email'] is going to be null or empty.

Also, don't pass $db as an argument to your readerthread_thread function. You're already declaring it globally, passing it as an argument to the function is just going to cause problems.
My Plugins: [1.8]|[1.6]

** Selling custom plugin that enables Bitcoin payments. PM me if interested in purchasing! **
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)