Link to home
Start Free TrialLog in
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
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of paulbsb
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!
You're welcome.