0

When I execute my, mysql query to database using PDO-mysql it will not insert the values. I am following the documentation but still don't seem to have made any progress.

So my .sql file is this

CREATE DATABASE IF NOT EXISTS `qr_db`; 

CREATE TABLE IF NOT EXISTS `qr_db`.`clients` (
    `id` int(11) NOT NULL auto_increment,
    `first_name` varchar(100) NOT NULL,
    `last_name` varchar(100) NOT NULL,
    `key` char(128) NOT NULL,
    PRIMARY KEY(`id`),
    UNIQUE KEY `key` (`key`)
) ENGINE=MyISAM;

grant select, insert, update, delete 
on qr_db.* 
to qr_db@localhost identified by 'password';

and this is the code I'm having trouble with

if(!isset($_GET['key'])) {

$mysql = db_connect();  // <--- this is ok i already checked this

$query = 'INSERT INTO `clients` (`first_name`, `last_name`, `hash`) VALUES (?, ?, ?)';

$stmt = $mysql->prepare($query);

$stmt->bindParam(1, $f_name, PDO::PARAM_STR);
$stmt->bindParam(2, $l_name, PDO::PARAM_STR);
$stmt->bindParam(3, $dubhash, PDO::PARAM_STR);
$stmt->execute();

} 
user3288619
  • 11
  • 1
  • 3

1 Answers1

-1

First check your connection if you connected with the database then use following the code to insert the record

Change hash in column name to key. this is creating problem because table don't have any column with name hash

 $sql = "INSERT INTO clients (first_name, last_name, key) VALUES (:fname, :lname, :hashval)";

$q = $mysql->prepare($sql);
$q->execute(array(':fname'=>$f_name,
                  ':lname'=>$lname,
                  ':hashval'=>$hash ));

Best of Luck...