0

For some reason, bind_param() says it's being called on a non-object, here is my script:

$con = new mysqli("localhost", "root", "", "lesea");

Here's where the query is being called:

var_dump($_POST['title']);
var_dump($_POST['description']);
var_dump($__final_route);
$stmt = $con->prepare("INSERT INTO post(title, content, image) VALUES(?, ?, ?)");
 $stmt->bind_param('sss', $_POST['title'], $_POST['description'], $__final_route);
if($stmt->execute()){
   echo "Post uploaded successfully!";
} else{
   echo "Post not uploaded due to an error, please try again.";
}

var_dump() provides string for each of the variables held inside the bind_param() method so I have no idea what is going on. Rookie mistake? It's been a while since I've done any back-end development. Any help would be much appreciated.

Cave Johnson
  • 6,499
  • 5
  • 38
  • 57
CodeTrooper
  • 1,890
  • 6
  • 32
  • 54
  • Prepare will return false if it fails; check for that, and if necessary, check what's in `mysqli_error($con)` - if your prepare calls fails, that will explain exactly why – andrewsi Mar 02 '16 at 00:32
  • It is unequivocally because it is being called on a non-object, probably because, as noted, the prepare fails and returns false (a boolean). You should enable error_reporting and make sure mysqli throws errors, there is a very evident error message that isn't getting to you that would tell you exactly what's the problem. – Félix Adriyel Gagnon-Grenier Mar 14 '17 at 22:43

0 Answers0