SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: PDO insert help

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    99
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    PDO insert help

    Hey there,

    My insert script was working then i think i screwed something up as it is not inserting the data any more

    PHP Code:
    try{
    $query 'INSERT INTO members  SET 
       email = :email,
       password = :password,
       nameFirst = :nameFirst,
       nameLast = :nameLast,
       farmName = :farmName, 
       groupNum = :groupNum'

     
     
    $s $dbconnect->prepare($query);
     
     
    $s->bindValue(':email'$email);
     
    $s->bindValue(':password'$password);
     
    $s->bindValue(':nameFirst'$nameFirst);
     
    $s->bindValue(':nameLast'$nameLast);
     
    $s->bindValue(':farmName'$farmName);
     
    $s->bindValue(':groupNum'$groupNum);
     
     
    $s->execute();
     
    header('Refresh: 5; url = http://ageasy.ca');
     echo 
    'Your account has been added you can now login!';
     echo 
    'You well now be redirected to the home page';
    }

    catch(
    PDOException $e)
        {
            echo 
    'there was an error inserting you account to the database: '.$e->getMessage();
        } 
    that's the sql insert. And yes i know it could use the bindValues with an array. I get the "Your account has been added you can now login" meaning it thinks it has been successful, but then when i go look in PMA (PhpMyAdmin) the data is not showing up. And connection seems to be ok as i am not getting any errors connecting.

    Thanks for the help in advance!

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    From memory TRY CATCH exception handlers don't respond to true and false which is what $s->execute() would be doing, simply get rid of it and use an IF ELSE statement instead.

    PHP Code:
    if ($s->execute()) {
        
    header('Refresh: 5; url = http://ageasy.ca');
        echo 
    'Your account has been added you can now login!';
        echo 
    'You well now be redirected to the home page';
    } else {
        echo 
    "\nPDOStatement::errorInfo():\n";
        
    $arr $sth->errorInfo();
        
    print_r($arr);

    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •