By RD7


2016-05-02 12:20:50 8 Comments

I try to bind parameters to sql (mysqli) in php, but there is an error code as written above. This is the code I wrote:

$stmt = $conn->prepare("INSERT INTO assignments (Classes_has_Subjects_classesHasSubjectsId, assignmentName, gradeForAssignment,protectiveGrade) 
                                  VALUES (?, ?, ?, ?)");
if ($stmt = false)
{
    echo "false";
}
else{
    $stmt->bind_param("sss", $classesHasSubjectsId, $assignmentName, $gradeForAssignment,  $protectiveGrade);
    $stmt->execute();
}

and here is the error message: 11

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

What's wrong?

1 comments

@D14n4 2016-05-02 12:38:50

<?php
$stmt = $conn->prepare("INSERT INTO assignments (Classes_has_Subjects_classesHasSubjectsId, assignmentName, gradeForAssignment,protectiveGrade) 
                                  VALUES (?, ?, ?, ?)");
    if (!$stmt) {
        echo "false";
    }
    else {
        $stmt->bind_param("ssss", $classesHasSubjectsId, $assignmentName, $gradeForAssignment,  $protectiveGrade);
        $stmt->execute();
    }

if ($stmt = false) means you're assigning false to $stmt. Replace it with if (!$stmt).

You're binding 4 parameters but only providing 3 types of values. I added a s in the bind_param function, assuming all your values are string. If some of the values are integers replace the corresponding s with an i. If there are doubles, replace with a d.

Are you sure the first field's name in the assignments table is Classes_has_Subjects_classesHasSubjectsId?

Related Questions

Sponsored Content

36 Answered Questions

[SOLVED] Reference - What does this error mean in PHP?

18 Answered Questions

[SOLVED] Reference — What does this symbol mean in PHP?

15 Answered Questions

[SOLVED] Why shouldn't I use mysql_* functions in PHP?

  • 2012-10-12 13:18:39
  • Madara's Ghost
  • 214921 View
  • 2459 Score
  • 15 Answer
  • Tags:   php mysql database

0 Answered Questions

Call to a member function bind_param() on boolean when preventing SQL Injection

  • 2019-04-27 15:36:40
  • Nacio
  • 20 View
  • 0 Score
  • 0 Answer
  • Tags:   php mysql mysqli

0 Answered Questions

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

  • 2018-09-27 11:00:55
  • Thomas Athanasiou
  • 22 View
  • 0 Score
  • 0 Answer
  • Tags:   php mysql mysqli

2 Answered Questions

3 Answered Questions

[SOLVED] Trouble using prepare and bind_param in php

  • 2015-07-22 11:57:08
  • Kex
  • 37 View
  • -1 Score
  • 3 Answer
  • Tags:   php mysql mysqli

1 Answered Questions

[SOLVED] mySQLi insert error - Call to a member function bind_param

  • 2016-03-22 15:45:27
  • med k
  • 875 View
  • 0 Score
  • 1 Answer
  • Tags:   php mysqli

1 Answered Questions

[SOLVED] Is there any know issue with PHP 5.3.29 and $stmt->get_result() function?

  • 2015-03-20 17:55:01
  • wittich
  • 459 View
  • 0 Score
  • 1 Answer
  • Tags:   php mysql mysqli

Sponsored Content