PHP函数(添加记录)无法正常工作

I am working on a website which will have a user adding form. The following function is addrecord(). When the admin user is creating a new user, this function adds the rows in the SQL table. But, every time I add a new users, I stucked at the error message "User name/password not added to contact", at the first else statement. When I check the table, the access level and password fields are having the data, but I cannot log in with the hashed password. Anybody could help, what's wrong with this code?

Thanks, Sixxdog

public function addRecord() {  

    // Verify the fields
    if ($this->_verifyInput()) {
        // prepare for the encrypted password
        $password = trim($_POST['password1']);

        // Get the Database connection
        $connection = Database::getConnection();

        // Prepare the data 
        $query = "INSERT INTO contacts(first_name, last_name, position, email, phone) 
        VALUES ('" . Database::prep($this->first_name) . "',
        '" . Database::prep($this->last_name) . "',
        '" . Database::prep($this->position) . "',
        '" . Database::prep($this->email) . "',
        '" . Database::prep($this->phone) . "')";
        // Run the MySQL statement 
        if ($connection->query($query)) { // this inserts the row
            // update with the user name and password now that you know the id
            $query = "UPDATE contacts 
            SET user_name = '" . Database::prep($this->user_name) . "', 
            password = '" . hash_hmac('sha512',
              $password . '!hi#HUde9' . mysql_insert_id(), 
              SITE_KEY) ."',
            access = '" . Database::prep($this->access) . "'";
            if ($connection->query($query)) { // this updates the row
              $return = array('', 'Contact Record successfully added.', '');   
              // add success message
              return $return;
            } else {
              // send fail message 
                $return = array('', 'User name/password not added to contact.', '');
                return $return;
            }

        } else {
            // send fail message and return to contactmaint
            $return = array('contactmaint', 'No Contact Record Added. Unable to create record.', '0');
            return $return;
        }
    } else {
        // send fail message and return to contactmaint
        $return = array('contactmaint', 'No Contact Record Added. Missing required information
        or problem with user name or password.', '0');
        return $return;
    }

}

There's no WHERE clause in your update statement. Perhaps the user_name column has a unique index on it?