Jump to content

call to a member function; how to solve?


Balderick

Recommended Posts

Hi people

 

I have a table created like this:

        --
	-- Database: `mydatabase`
	--

	-- --------------------------------------------------------

	--
	-- Tablestructure for table `table_name`
	--

	CREATE TABLE `table_name` (
	  `num` int(4) NOT NULL,
	  `fol_num` int(7) DEFAULT NULL,
	  `col3` varchar(30) DEFAULT NULL,
	  `col4` int(1) DEFAULT NULL,
	  `num_nonce` varchar(20) DEFAULT NULL,
	  `col6` varchar(30) DEFAULT NULL,
	  `col7` varchar(15) DEFAULT NULL,
	  `col8` varchar(15) DEFAULT NULL
	) ENGINE=MyISAM DEFAULT CHARSET=latin1;

	--

I also created a function and the goal of the function is to read the random number from fol_num with a mysql query with WHERE.

fol_num should match with the number found and show num_nonce belonging to that record.

 

query:

     SELECT num_nonce, FROM table_name WHERE fol_num = ? ;

function:

    <?php  

	function my_func() {
		
		
		// global
		global $fol_num;
		global $num_nonce;
		
	$servername = "localhost";
	$username = "myname";
	$password = "mypassword";
	$dbname = "mydatabase";

	// Create connection
	$conn = new mysqli($servername, $username, $password, $dbname);

	// Check connection
	if ($conn->connect_error) {
		die("Connection failed: " . $conn->connect_error);
	}

	   
	   
	   var_dump($fol_num);
	   
	   // select nonce from database table
	   
	$stmt = $conn->prepare("SELECT num_nonce, FROM table_name WHERE fol_num = ? ;" ) ;

		$stmt->bind_param('is', $fol_num, $num_nonce);
	 
   		$stmt->execute();
		 
		$stmt->bind_result($fol_num, $num_nonce);
		$stmt->fetch();
		
		var_dump($num_nonce);

 	//	var_dump($fol_num2);
			
		 

	//$stmt->close();
			$conn->close();

	}

	my_func();
        ?>

I receive errors that sound like:

 

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in ......

 

pointing to this line:

 

$stmt->bind_param('is', $fol_num, $num_nonce);

 

what is not good and how to solve it?

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...