Page 1 of 1

PDO Insert Query not running - and no error

Posted: Mon Sep 11, 2017 3:39 am
by simonmlewis
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.

Code: Select all

$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));

Re: PDO Insert Query not running - and no error

Posted: Mon Sep 11, 2017 12:30 pm
by requinix
What $result successfully prepared? What does ->execute() return? What do you have the PDO error reporting setting as?

Re: PDO Insert Query not running - and no error

Posted: Tue Sep 12, 2017 5:26 am
by Celauran
Hang on. PDO::query executes the query. You're then passing the results of that to PDO::prepare. Skip the first step and just pass the query string to PDO::prepare.

Re: PDO Insert Query not running - and no error

Posted: Tue Sep 12, 2017 5:39 am
by simonmlewis
Yes I just noticed that too. I've got two of them. It's sorted now thanks.