0

I'm trying to insert data into my database using php prepared statements. Problem is, this error keeps showing up.

Fatal error: Uncaught Error: Call to a member function bind_param() on bool

There's nothing wrong with my connection to the database. Seeing as it's recognizing my query as a bool, I know here's an error somewhere, but I don't know what exactly it is.

Here's the code for reference :

    if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $message = $_POST['message'];

    $query = $connect -> prepare("INSERT INTO userinfo (nickname,secret) VALUES(?.?)");
    $query -> bind_param('ss',$name,$message);
    if ($query->execute) {
        echo "~Your secret has been SPILLED.";
    } else{
        echo "~There was an error submitting your secret!";
    }
}else{
    echo"Error, slippery button syndrom";
}
Newbie19
  • 13
  • 2
  • If you enable error reporting for mysqli you will see an error pointing you to `?.?`. – Dharman Dec 21 '21 at 13:00
  • in your valzues you have ?.? but it should be ?,? your SQL is wrong so $query is false – Vitalij Mik Dec 21 '21 at 13:00
  • @Dharman I corrected that error and yet the error is still there. – Newbie19 Dec 21 '21 at 13:07
  • @VitalijMik Fixed it and the same error remains – Newbie19 Dec 21 '21 at 13:07
  • Did you enable mysqli error reporting? – Dharman Dec 21 '21 at 13:07
  • @Newbie19 $query = $connect -> prepare("INSERT INTO userinfo (nickname,secret) VALUES(?,?)"); if(!$query){ die($connect->error); } – Vitalij Mik Dec 21 '21 at 13:11
  • @Dharman Now I have.. the issue was that I entered the wrong database name. Talk about embarrassing. Thanks for your help – Newbie19 Dec 21 '21 at 13:14
  • @VitalijMik I did it. The error was from my database name. Thank you for your help! – Newbie19 Dec 21 '21 at 13:15
  • @VitalijMik That's a very bad idea. Please don't recommend that. – Dharman Dec 21 '21 at 13:15
  • @Dharman please explain, the author does not know how to enable error reporting and does not know how to see the errors, this is just a quick and dirty way to get the information from the author. ofc is die bad in a real code but often you have other frameworks around whcih blocks the output. in order to explain it properly you need to add much more code. and as you could see from his response, it actually worked – Vitalij Mik Dec 21 '21 at 13:19
  • I have literally provided an answer explaining how to enable mysqli error reporting. It's a single line of code that you put in your code. It's much easier and safer than putting `die` everywhere in the code. There's no reason to use `die` at all. – Dharman Dec 21 '21 at 13:20
  • @Dharman where did you provided the answer? in this comments you just asked if he has enabled it. iam know that there is no reason to use die but in this case, based on the code it is easier to show it this way – Vitalij Mik Dec 21 '21 at 13:42
  • 1
    @VitalijMik There is a big blue box at the top of the question. It links to this page https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param There you can find an explanation of how to enable mysqli error reporting. – Dharman Dec 21 '21 at 13:44
  • @Dharman ah i see, then aim sorry. why not mention it in first place :D – Vitalij Mik Dec 21 '21 at 13:45

0 Answers0