Hi guys, i'm getting all my cod to PDO, but no luck for my side, and PDO is killing me!
i've this table

CREATE TABLE IF NOT EXISTS `tbl_organization` (
  `id_organization` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `registered_name` varchar(100) DEFAULT NULL,
  `registration_number` varchar(15) DEFAULT NULL,
  `id_business_type` int(11) DEFAULT NULL,
  `id_location` int(11) NOT NULL,
  `id_entity` int(11) DEFAULT NULL,
  `date_created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `date_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `user_created` varchar(100) DEFAULT NULL,
  `user_modified` varchar(100) DEFAULT NULL,
  `id_audit_type` int(11) DEFAULT NULL,
  `flag_active` tinyint(1) DEFAULT NULL,
  `lock_stamp` int(11) DEFAULT NULL,
  PRIMARY KEY (`id_organization`),
  KEY `id_entity` (`id_entity`),
  KEY `id_location` (`id_location`),
  KEY `FK_BUSI_TYPE` (`id_business_type`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

And i'm tryng to insert data by form, and my php cod is:

<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


include_once 'dbal.php';


        if(isset($_POST['submit'])):

        $name = $_POST["name"];
        $registered_name = $_POST["registered_name"];
        $registration_number =$_POST["registration_number"];
        $id_business_type = $_POST["id_business_type"];
        $id_location = $_POST["id_location"];
        $id_entity = 1;
                $date_modified = '2011-12-11';
                $date_modified = '2013-12=12';
        $user_created = 'Admin';
        $user_modified = 'Admin';
        $id_audit_type = 1;
        $flag_active = 1;
        $lock_stamp = 1; 

               $sql  = 'INSERT INTO tbl_organization(name, registered_name, registration_number, id_business_type, id_location, id_entity, date_created, date_modified, user_created, user_modified, id_audit_type, flag_active, lock_stamp)';
               $sql .='VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
               try {
                   $create = $db->prepare($sql);
                   $create ->bindValue(':name', $name, PDO::PARAM_STR);
                   $create ->bindValue(':registered_name', $registered_name, PDO::PARAM_STR); 
                   $create ->bindValue(':registration_number', $registration_number, PDO::PARAM_INT); 
                   $create ->bindValue(':id_business_type', $id_business_type, PDO::PARAM_INT); 
                   $create ->bindValue(':id_lcation', $id_lcation, PDO::PARAM_INT); 
                   $create ->bindValue(':id_entity', $id_entity, PDO::PARAM_INT); 
                   $create ->bindValue(':date_created', $date_created, PDO::PARAM_STR); 
                   $create ->bindValue(':date_modified', $date_modified, PDO::PARAM_STR); 
                   $create ->bindValue(':user_created', $user_created, PDO::PARAM_STR); 
                   $create ->bindValue(':user_modified', $user_modified, PDO::PARAM_STR); 
                   $create ->bindValue(':id_audit_type', $id_audit_type, PDO::PARAM_INT); 
                   $create ->bindValue(':flag_active', $flag_active,  PDO::PARAM_INT); 
                   $create ->bindValue(':lock_stamp', $lock_stamp,  PDO::PARAM_INT); 

                   if($create->execute()){
                       echo 'sucess';
                   }

               } catch (PDOException $e) {
                   echo 'wrong way'.$e->getMessage();
               }
        endif;

but nothing is working for me and i don't know where is the bug.
The error message i receive from mysql is:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

So can someone help me figure out, and also i tryed making class, but nothing helpful, on class when i run, i get blank page.
Please guys

If you bind values by name, you must use those names in your query, instead of the question marks:

$sql .='VALUES (:name, :registered-name, ... and so on

Hi Pritaeas, Before use "?", i was using some like what u recomend, but nothing is working!

 $sql  = 'INSERT INTO tbl_organization(name, registered_name, registration_number, id_business_type, id_location, id_entity, date_created, date_modified, user_created, user_modified, id_audit_type, flag_active, lock_stamp)';
               $sql .='VALUES (:name, :registered_name, :registration_number, :id_business_type, :id_location, :id_entity, :date_created, :date_modified, :user_created, :user_modified, :id_audit_type, :flag_active, :lock_stamp)';
               try {
                   $statement = $db->prepare($sql);
                   $statement ->bindValue(':name', $name);
                   $statement ->bindValue(':registered_name', $registered_name); 
                   $statement ->bindValue(':registration_number', $registration_number); 
                   $statement ->bindValue(':id_business_type', $id_business_type); 
                   $statement ->bindValue(':id_lcation', $id_lcation); 
                   $statement ->bindValue(':id_entity', $id_entity); 
                   $statement ->bindValue(':date_created', $date_created); 
                   $statement ->bindValue(':date_modified', $date_modified); 
                   $statement ->bindValue(':user_created', $user_created); 
                   $statement ->bindValue(':user_modified', $user_modified); 
                   $statement ->bindValue(':id_audit_type', $id_audit_type); 
                   $statement ->bindValue(':flag_active', $flag_active); 
                   $statement ->bindValue(':lock_stamp', $lock_stamp); 

I used but nothing! want correct!
The erro is:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

I don't know what's going in my machine!

want correct!

I want a lot of things.. If you don't post what you have, I can't help. According to the error one of your parameters is not defined.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.