www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] PDO error of some sort

  1. #1
    Join Date
    Jun 2009
    Location
    Chi town. IL68 ICAO code home airport, literally.
    Posts
    157

    resolved [RESOLVED] PDO error of some sort

    So I wrote this script, and it works when i dont bind the "Random_Key" and use it as it is, but when I bind the key with bindParam() I am getting a error. Can you see whats going wrong?

    PHP Code:

    <?php
    //Fetches Random_Key from email to use in binding
    $Random_Key $_GET['c'];

        
    //Sets other variables for later use
        
    $ERRmsg "";
        
    $validCount 0;
        
            
    //Opens a connection to MySQL
            
    try {
                
    $wdp = new PDO('mysql:host=localhost; dbname=***********''***********''******');
                
    $wdp->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
                    
    //prepare the SQL statement
                    
    $sth $wdp->prepare(
                    
    "SELECT
                    user_email,
                    Active
                    FROM
                    Users
                    WHERE
                    Random_Key = :key
                    "
    );
                    
                        
    //binds the key for safety
                        
    $sth->bindParam(':key'$Random_Key);
                    
                        
    //Excutes the SQL statement
                        
    $sth->execute();

                            
    //Sets the statement into an array
                            
    $result $sth->fetch(PDO::FETCH_ASSOC);
                                
    $active $result[Active];
                                
    $email $result[user_email];
                            
                                
    //Checks if account already active
                                
    if($active == 1$ERRmsg .= "You have already confirmed this account. <br/>";
                                if(
    $active == 3$ERRmsg .="Your account has been disabled for securty reasons, contact the Web Admin for more info";
                                    
                                    
    //checks to see if error message is empty, if so continues if not throws error
                                    
    if(empty($ERRmsg))
                                    {
                                        
    //If everything passes connects back to Database and updates to make account active
                                        
    $update $wdp->prepare(
                                        
    "UPDATE
                                        Users
                                        SET
                                        Active = '1'
                                        Where
                                        Random_Key= :key
                                        "
    );
                                        
                                                            
    //binds the key for safety
                                                            
    $sth->bindParam(':key'$Random_Key);

                                            
    //Exectures the update
                                            
    $update->execute();
                                            echo (
    "<p>Your account has been confirmed!");
                                    }
                                        else
                                        {
                                            echo 
    $ERRmsg;
                                        }
                
                }
                catch (
    PDOException $ex) {
                
    $msg $ex->errorInfo;
                
    error_log(var_export($msgtrue));
                die(
    "<p>Sorry, there was an unrecoverable database error. Debug data has been logged.</p>");
                                                        };
    ?>
    For want of a nail...the horseshoe was lost. For want of a horseshoe, the steed was lost. For want of a steed...the message was not delivered. For want of an undelivered message.....the war was lost.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,338
    What is the error? Is something output to the error log?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2009
    Location
    Chi town. IL68 ICAO code home airport, literally.
    Posts
    157
    My favorite error....

    PHP Code:
    [24-Nov-2012 16:25:35] array ( 
      
    => 'HY093'
      
    => 0

    For want of a nail...the horseshoe was lost. For want of a horseshoe, the steed was lost. For want of a steed...the message was not delivered. For want of an undelivered message.....the war was lost.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,338
    Here's a hint:

    Code:
    $update = $wdp->prepare(
    "UPDATE
    Users
    SET
    Active = '1'
    Where
    Random_Key= :key
    ");
    
    //binds the key for safety
    $sth->bindParam(':key', $Random_Key);
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jun 2009
    Location
    Chi town. IL68 ICAO code home airport, literally.
    Posts
    157
    Of course!
    For want of a nail...the horseshoe was lost. For want of a horseshoe, the steed was lost. For want of a steed...the message was not delivered. For want of an undelivered message.....the war was lost.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles