Avatar of paulbsb
paulbsb
 asked on

Problem inserting info into a MySQL DB

I'm new to this site, php/MySQL and I'm trying to insert text and links into a db. This is the error I get, and below  is the code.

 mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables in /home/content/53/7284053/html/1-newsite/admin/input.php on line 15

<?php
if (isset($_POST['insert'])) {
  require_once('../includes/connection.inc.php');
  // initialize flag
  $OK = false;
  // create database connection
  $conn = dbConnect('write');
  // initialize prepared statement
  $stmt = $conn->stmt_init();
  // create SQL
  $sql = 'INSERT INTO paintings (title, image, thumb, created)
              VALUES(?, ?, ?, NOW())';
  if ($stmt->prepare($sql)) {
      // bind parameters and execute statement
      $stmt->bind_param('ss', $_POST['title'], $_POST['image'], $_POST['thumb']);
    // execute and get number of affected rows
      $stmt->execute();
      if ($stmt->affected_rows > 0) {
        $OK = true;
      }
  }
  // redirect if successful or display error
   
  if ($OK) {
        
      header('Location: http://paulbdotcom.db.7284053.hostedresource.com/paulbdotcom/admin/manage_paintings.php');
      exit;
  } else {
      $error = $stmt->error;
  }
}
?>

This is the page I'm trying to make work:
http://www.paulb.com/1-newsite/admin/input.php

Thanks very much,
Paul
MySQL ServerScripting LanguagesWeb-Based CMS

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
paulbsb

ASKER
It was a very simple solution but I'm new to php and didn't know how to fix that. Now I understand how to do it. I now have a better understanding of the php language. Thank you!
Dave Baldwin

You're welcome.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck