0

So I'm having the same problem for 3 hours straight and I've been searching Stack Overflow, Google and even Bing (yes even Bing..) for the right answer but I can't seem to find a solution...

The problem:

I try to insert data into my database using a prepared statement, but I keep getting the same error over and over again. I'm using everything in the right order and stuff so that's not the mistake...

My code:

//INCLUDES FILES THAT HOLD ALL DATA (servername, username, ...)

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

 // prepare and bind
 $stmt = $conn->prepare("INSERT INTO REGISTRY (user_ref, email_user, date_created, title, tweet, description, category, filename, invoice) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
 $stmt->bind_param("sssssssss", $gebruikerID, $email, $date_created, $title, $tweet, $description, $category, $nameImage, $customUniqueId);

// set parameters and execute
$gebruikerID = $gebruikerID;
$email = $email;
$date_created = date("d/m/Y H:i:s");
$title = date("d/m/Y H:i:s");
$tweet = $_POST["tweet"];
$description = $_POST["project_description"];
$category = $_POST["category"];
$nameImage = $nameImage;
$customUniqueId = $_GET["redirect"];

$stmt->execute();

echo "New records created successfully";

$stmt->close();
$conn->close();

The error I'm getting for 3 hours straight:

Fatal error: Call to a member function bind_param() on a non-object on line 148

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
CoderYordi
  • 57
  • 9

1 Answers1

0

For those of you that have the same problem like me, here's what was wrong:

I had forgotten to put every row of my database in the code... So what I ended up was go to phpmyadmin and go to the table i wanted to insert some data in. Then I clicked SQL and I chose insert.

After that, I got a code and I replaced all [val-x] with ? And ended up with this code:

// prepare and bind
$stmt = $conn->prepare("INSERT INTO `projecten`(`user_ref`, `email_user`, `date_created`, `title`, `tweet`, `description`, `category`, `filename`, `invoice`, `admin_checkup`, `visible`, `project_finished`, `deleted`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");

$stmt->bind_param("sssssssssssss", $gebruikerID, $email, $date_created, $title, $tweet, $description, $category, $nameImage, $customUniqueId, $adminCheck, $visible, $project_finished, $deleted);

// set parameters and execute
$gebruikerID = $gebruikerID;
$email = $email;
$date_created = date("d/m/Y H:i:s");
$title = date("d/m/Y H:i:s");
$tweet = $_POST["tweet"];
$description = $_POST["project_description"];
$category = $_POST["category"];
$nameImage = $nameImage;
$customUniqueId = $_GET["redirect"];
$adminCheck = "0";
$visible = "0";
$project_finished = "0";
$deleted = "0";

$stmt->execute();

I hope this helps you guys out!

CoderYordi
  • 57
  • 9