Jump to content

help me please with fatal error.


seany123

Recommended Posts

Why am i getting this fatal error?

 

Fatal error: Call to a member function fetchrow() on a non-object

 


function getUsersName( $id )

			{

			global $config_server, $config_database, $config_username, $config_password;


			$db = new DB( $config_server, $config_username, $config_password, $config_database );

			$player2 = $db->searchQuery( "SELECT * FROM players WHERE id = '" . $id . "'" );
			$name = $player2->fetchrow();
			$exists = $player2->recordcount();
			if ($exists == 1){
			return $player2[0][ 'username' ];
			}
			else{
			return $player->username;	
			}

			} // ends function...

 

anyone know?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/180857-help-me-please-with-fatal-error/
Share on other sites

There is no point in randomly trying code or guessing what the code should be. What database class are you using so that someone could tell you how to do some error checking, error reporting, and error recovery to get it to tell you why the query is failing?

i tried editing the code a little and now im getting this error:

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1

 

 

function getUsersName( $id )

			{

			global $config_server, $config_database, $config_username, $config_password;

			$db = new DB( $config_server, $config_username, $config_password, $config_database );	



			$player2 = $db->searchquery('select * from `players` where `id`=?', array($id));
			$name = $player2->fetchrow();
			$exist = $player2->recordcount();
			if ($exist == 1){
			return $player2[0][ 'username' ];
			}
			else if($exist <= 0){
			return $player->username;	
			}

			} // ends function...

you need to tell us what Database class you are using. or at least show the searchquery method. Without that information, any advice we could give would be shots in the dark.

 

by the way you only need to use backticks when you are using reserved words in mysql

 

you need to tell us what Database class you are using. or at least show the searchquery method. Without that information, any advice we could give would be shots in the dark.

 

by the way you only need to use backticks when you are using reserved words in mysql

 

 

okay i removed the backticks...

 

here is the function for the searchQuery:

 

public function searchQuery( $sql )

		{

		$query = $this->query( $sql );

		return $this->returnArray( $query );

		} // ends method...

 

code im using now and still getting same error:

 

function getUsersName( $id )

			{

			global $config_server, $config_database, $config_username, $config_password;


			$db = new DB( $config_server, $config_username, $config_password, $config_database );


			$player2 = $db->searchQuery("select * from players where id=?", array($id));
			$name = $player2->fetchrow();
			$exist = $player2->recordcount();
			if ($exist == 1){
			return $player2[0][ 'username' ];
			}
			else if($exist <= 0){
			return $player->username;	
			}

			} // ends function...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.