PHP Developers Network
http://forums.devnetwork.net/

PDO Insert Query not running - and no error
http://forums.devnetwork.net/viewtopic.php?f=2&t=144198
Page 1 of 1

Author:  simonmlewis [ Mon Sep 11, 2017 3:39 am ]
Post subject:  PDO Insert Query not running - and no error

This script is not running anything. It' snot doing any inserts, and not throwing up any errors.
How do I identify why is it not inserting anything?
If the db name or fields were incorrect, it would stop and through an error. It isn't.

Syntax: [ Download ] [ Hide ]
$today = (date('Y-m-d'));

// random code to be added to email for clarification
$random = (rand()%99999999);

                        $query = $pdo->query("INSERT INTO admin (firstname, lastname, email, created, password, address1, address2, town, county, postcode, `type`, telephone, drivinglicense, shift, status) VALUES (:firstname, :lastname, :email, :today, :password, :address1, :address2, :town, :county, :postcode, :user, :telephone, :drivinglicense, :shift, :random)");
                       
      $result = $pdo->prepare($query);
     
      $result->execute(array(':firstname' => $firstname, ':lastname' => $lastname, ':email' => $email, ':today' => $today, ':password' => $password, ':address1' => $address1, ':address2' => $address2, ':town' => $town, ':county' => $county, ':postcode' => $postcode, ':user' => $user, ':telephone' => $telephone, ':drivinglicense' => $drivinglicense, ':shift' => $shift, ':random' => $random));

Author:  requinix [ Mon Sep 11, 2017 12:30 pm ]
Post subject:  Re: PDO Insert Query not running - and no error

What $result successfully prepared? What does ->execute() return? What do you have the PDO error reporting setting as?

Author:  Celauran [ Tue Sep 12, 2017 5:26 am ]
Post subject:  Re: PDO Insert Query not running - and no error

Hang on. executes the query. You're then passing the results of that to . Skip the first step and just pass the query string to PDO::prepare.

Author:  simonmlewis [ Tue Sep 12, 2017 5:39 am ]
Post subject:  Re: PDO Insert Query not running - and no error

Yes I just noticed that too. I've got two of them. It's sorted now thanks.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/