Solved

Problem inserting info into a MySQL DB

Posted on 2013-11-12
3
351 Views
Last Modified: 2013-11-13
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
0
Comment
Question by:paulbsb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39643150
You're probably missing an 's' because you have three values but only two format specs.
$stmt->bind_param('sss', $_POST['title'], $_POST['image'], $_POST['thumb']);

Open in new window

0
 

Author Closing Comment

by:paulbsb
ID: 39645822
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!
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39645939
You're welcome.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question