Click here to Skip to main content
14,544,540 members
Rate this:
Please Sign up or sign in to vote.
See more:
i keep on getting this error
Fatal error: Uncaught Error: Call to a member function bind_param() on bool in /Users/Tobo/Sites/prototype/connect.php:193 Stack trace: #0 {main} thrown in /Users/Tobo/Sites/prototype/connect.php on line 193

This is my code

<?php












if(isset($_POST['Documentno'])){
    $Documentno = $_POST['Documentno'];
}
if(isset($Documentno)){ 
    echo $Documentno;
}



if(isset($_POST['DocumentCategory'])){
    $DocumentCategory = $_POST['DocumentCategory'];
}
if(isset($DocumentCategory)){ 
    echo $DocumentCategory;
}


if(isset($_POST['CertificateNo'])){
    $CertificateNo = $_POST['CertificateNo'];
}
if(isset($CertificateNo)){ 
    echo $CertificateNo;
}


if(isset($_POST['Revision'])){
    $Revision = $_POST['Revision'];
}
if(isset($Revision)){ 
    echo $Revision;
}



if(isset($_POST['Duedate'])){
    $Duedate = $_POST['Duedate'];
}
if(isset($Duedate)){ 
    echo $Duedate;
}





if(isset($_POST['IMCAD018ref'])){
    $IMCAD018ref = $_POST['IMCAD018ref'];
}
if(isset($IMCAD018ref)){ 
    echo $IMCAD018ref;
}


if(isset($_POST['DESIGNAuditref'])){
    $DESIGNAuditref = $_POST['DESIGNAuditref'];
}
if(isset($DESIGNAuditref)){ 
    echo $DESIGNAuditref;
}


if(isset($_POST['Description'])){
    $Description = $_POST['Description'];
}
if(isset($Description)){ 
    echo $Description;
}


if(isset($_POST['Make'])){
    $Make = $_POST['Make'];
}
if(isset($Make)){ 
    echo $Make;
}


if(isset($_POST['AssetNumber'])){
    $AssetNumber = $_POST['AssetNumber'];
}
if(isset($AssetNumber)){ 
    echo $AssetNumber;
}


if(isset($_POST['COMMENTS'])){
    $COMMENTS = $_POST['COMMENTS'];
}
if(isset($COMMENTS)){ 
    echo $COMMENTS;
}


if(isset($_POST['TestProcedureRef'])){
    $TestProcedureRef = $_POST['TestProcedureRef'];
}
if(isset($TestProcedureRef)){ 
    echo $TestProcedureRef;
}




if(isset($_POST['PlaceofInspection'])){
    $PlaceofInspection = $_POST['PlaceofInspection'];
}
if(isset($PlaceofInspection)){ 
    echo $PlaceofInspection;
}





if(isset($_POST['DateofInspection'])){
    $DateofInspection = $_POST['DateofInspection'];
}
if(isset($DateofInspection)){ 
    echo $DateofInspection;
}



if(isset($_POST['DateofNextInspection'])){
    $DateofInspection = $_POST['DateofNextInspection'];
}
if(isset($DateofNextInspection)){ 
    echo $DateofNextInspection;
}




if(isset($_POST['TestResults'])){
    $TestResults = $_POST['TestResults'];
}
if(isset($TestResults)){ 
    echo $TestResults;
}



if(isset($_POST['Doneby'])){
    $Doneby = $_POST['Doneby'];
}
if(isset($Doneby)){ 
    echo $Doneby;
}




if(isset($_POST['Approval'])){
    $Approval = $_POST['Approval'];
}
if(isset($Approval)){ 
    echo $Approval;
}


if(isset($_POST['Date'])){
    $Date = $_POST['Date'];
}
if(isset($Date)){ 
    echo $Date;
}



	
	//. database connection code
 $conn = new mysqli('127.0.0.1', 'root', 'toboroot', 'sys');

if($conn->connect_error){
die('Connection Failed : '.$conn->connect_error);
}else{
$stmt = $conn->prepare("insert into database(Documentno, DocumentCategory, DepartmentOwner, CertificateNo, Revision, Duedate, IMCAD018ref, DESIGNAuditref, Description, Make, AssetNumber, COMMENTS, TestProcedureRef, PlaceofInspection, DateofInspection, DateofNextInspection, TestResults, Doneby, Approval, Date ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");


$stmt->bind_param("ssssssssssssssssssss", ['Documentno'], ['DocumentCategory'], ['DepartmentOwner'], ['CertificateNo'], ['Revision'], ['Duedate'], ['IMCAD018ref'], 
  ['DESIGNAuditref'], ['Description'], ['Make'], ['AssetNumber'], ['COMMENTS'], ['TestProcedureRef'], ['PlaceofInspection'], ['DateofInspection'], ['DateofNextInspection'], ['TestResults'], ['Doneby'], ['Approval'], ['Date']);

$stmt->execute();
	echo "Record stored";
		$stmt->close();
		$conn->close();
}
?>


What I have tried:

trying changing the quotes of the field names from 'to ` as someone suggested.didnt work
Posted
Updated 23-May-20 14:57pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

What it means is there was a problem when you ran prepare()[^]
1. Check the value of $stmt before you bind; it should be a boolean
2a. If this value is false; check the query to make sure table and columns are correct.
2b. Otherwise, you should be able to do the binding and execution.

Reference:
PHP: mysqli_stmt::prepare - Manual[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Yes it was definitely a probably when i ran prepare.

Changed insert into from lower case to upper case and database into boat, which is the name of the table and it started working .

Thanks for your help. I appreciate it
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100