Solved

Problem inserting info into a MySQL DB

Posted on 2013-11-12
3
336 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
  • 2
3 Comments
 
LVL 82

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 82

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now