?
Solved

Problem inserting info into a MySQL DB

Posted on 2013-11-12
3
Medium Priority
?
356 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 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