Call to a member function bind_param() on boolean

error part is $queryReference->bind_param(“s”,$_POST[‘reference_number’])

if(empty($errors)):
		$sqlReference = "SELECT count(id) as reference_cnt FROM payments WHERE reference_number = ?";
			$queryReference = $db->prepare($sqlReference);		
			$queryReference->bind_param("s",$_POST['reference_number']); 		
			$queryReference->execute();
			$resultReference = $queryReference->get_result();
			$rowReference = $resultReference->fetch_assoc();
		if(!empty($rowReference['reference_cnt'])) {
			array_push($errors,"This Reference Number already exists");
		} 
	endif;
	if(empty($errors)):

The error is because the prepare() call failed and you don’t have any error handling to tell you if and why a database statement failed.

This code is attempting to do the same thing as in one of your previous threads - Trying to check if block_lot_no is already existing using prepared statements I recommend that you reread that thread and do the things mentioned in the replies, concerning just attempting to INSERT the data and detecting in the error handling if a duplicate index error occurred. The suggested usage of exceptions for database statement errors will also tell you why the prepare call is failing in this code.

Okay thanks.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.