Cancel that:

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);

should be:

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

The error with the code was displayed after fixing that, allowing me to debug 
the issue further up in the code.

Cheers
Aaron
  ----- Original Message ----- 
  From: Aaron Cooper 
  To: [email protected] 
  Sent: Wednesday, November 26, 2008 12:22 PM
  Subject: [phpug] PDO Prepared Insert Failing


  Hi all. Can anyone see a problem with this simple script? It's not inserting, 
and the final try catch block is not throwing. But a "or die()" on the 
$stmt->execute line will fire.

  try {
      $dbh = new PDO("mysql:host=localhost;dbname=glasscorp","user","password");
    }
    catch (PDOException $e) {
      echo $e->getMessage();
    }
    
    $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
    
    // If the form has been submitted - add the user to the system
    if(isset($_POST['action']) && $_POST['action'] == 'add') {
      
      $firstname = $_POST['firstname'];
      $surname = $_POST['surname'];
      $email = $_POST['email'];
      $company = $_POST['company'];
      $date_registered = date("Y-m-d H:i:s");
      $password = md5($_POST['auto_password']); 
      
      // Insert record, setting flag if success    
      try {
        $stmt = $dbh->prepare("INSERT INTO certs_users 
(firstname,surname,company,email,password,date_registered) VALUES (:firstname, 
:surname, :company, :email, :password, :date_registered )");
        $stmt->bindParam(':firstname', $firstname);
        $stmt->bindParam(':surname', $surname);
        $stmt->bindParam(':email', $email);
        $stmt->bindParam(':company', $company);
        $stmt->bindParam(':password', $password);
        $stmt->bindParam(':date_registered', $date_registered);
        $stmt->execute();
      } 
      catch (PDOException $e) {
        print $e->getMessage();
      }

  Cheers
  Aaron 

  

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to