I’ve been trying for the past 10 hours or so trying to solve this PHP fatal error. I’ve looked all over Stack Overflow, and many more sites to find the solution. Unfortunately, I have not found the missing piece and I’m humbly asking for a hand.
The error is: **Fatal error** : Uncaught Error: Call to a member function bind_param() on bool in C:\xampp\htdocs\affc\index.php:48 Stack trace: #0 {main} thrown in **C:\xampp\htdocs\affc\index.php** on line **48**
My code is as follows.
$conn=mysqli_connect("localhost","","",""); /* This is connected properly. For the sake of my database privacy, I am not disclosing it. */
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
if(isset($_POST['submit']))
{
$post_user = $_POST['content'];
$save = $conn->prepare("INSERT INTO psots (status_id, status, timestamp) VALUES ?,?,?");
$save->bind_param("sss",$post_user);
$save->execute();
if(!$insert)
{
echo mysqli_error();
}
else
{
echo "Records added successfully.";
}
}```
Unless $post_user is an array of 3 parameters (which it likely isnt), this will fail. You’re telling bind_param you’re going to send it 3 things, and then only giving it one.
Again, these aren’t parentheses. These are double quotation marks. If you are having issues with understanding what a parentheses is, look at your current SQL query.
Looks like I stroked out, but putting it in parentheses arises a new error:
Warning : mysqli_stmt::bind_param(): Number of variables doesn’t match number of parameters in prepared statement in C:\xamppest\htdocs\affc\index.php on line 48
Alright, so this error actually pertains to your original parameter numbers. They were correct, but you were just only passing in 1. You are expected to pass in the same amount of variables in bind_param as the same amount of data types. All of this should correlate with your actual SQL query. So you have to be passing in 3 things in your SQL query, in the data type option, and your variables.
#1: Unless you’ve done some very creative naming of MySQL tables, you’ve typoed the table name. #2: If you’re going to put a timestamp on the entry, you’re probably using the default value of CURRENT_TIMESTAMP anyway, and can probably eliminate it from the query if that’s the case. #3: If status_id is an INT, you’ll need to pass an int, not a string for that parameter. #4: You need to pass three (or two, if you eliminated timestamp in #2) parameters, of the correct type.