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
Share on other sites

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

Link to comment
Share on other sites

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

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.