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

20 Answered Questions

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

36 Answered Questions

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

13 Answered Questions

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

  • 2012-10-12 13:18:39
  • Madara's Ghost
  • 225877 View
  • 2530 Score
  • 13 Answer
  • Tags:   php mysql

Sponsored Content