• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB Insert -- Insert Query Errors out but insert happens???

#1
[eluser]drewbee[/eluser]
Hello All,

Just wanted to let you know I am new, but I am going through a very strange thing happening here.

Basically after posting the form, a database error is displayed. However, the insert successfully happens.

Any ideas on this one?

First Post (Successfully Inserts)
Code:
A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

1

I refresh the page (duplicate key entry, shows query used for insert)
Code:
A Database Error Occurred

Error Number: 1062

Duplicate entry 'testuser' for key 2

INSERT INTO `accounts` (`email`, `first_name`, `middle_initial`, `last_name`, `username`, `password`, `created`, `modified`, `account_type`, `account_group`, `account_lastlogin`, `account_status`) VALUES ('drewbdulgar@gmail.com', 'Drew', 'B', 'Dulgar', 'testuser', '0fa4c1b9a2fbd609fce8a1f71ec3f4b1', 1217555550, 1217555550, 1, 0, 0, 1)

Obviously I understand the second error (because even though the first post shows an error, it succesfully inserts.

I've been scratching my head on this one... Any advice would be greatly appreciated!!

Controller » _user_create()
Code:
function _user_create()
    {
        $data = array('email'                 => $this->input->post('email'),
                      'first_name'             => $this->input->post('first_name'),
                      'middle_initial'         => $this->input->post('middle_initial'),
                      'last_name'             => $this->input->post('last_name'),
                      'username'             => strtolower($this->input->post('username')),
                      'password'             => md5($this->validation->_salt_hash . $this->input->post('password_1')),
                      'created'                => time(),
                      'modified'            => time(),
                      'account_type'        => 1,
                      'account_group'        => 0,
                      'account_lastlogin'    => 0,
                      'account_status'        => 1);
        
        return $this->db->query($this->db->insert('accounts', $data));
    }

Controller » General Area of index() that called _user_create()
Code:
$this->validation->use_tokenizer();
        
        if ($this->validation->run() == FALSE)
        {
            $this->template->draw();
        }
        else
        {
            if ($this->validation->_tokenizer_dp == FALSE)
            {
                $this->_user_create();
            }
            
            $message = array('title'     => 'Registration Succesfull',
                             'message'    => 'Your account has been succesfully registered!');
            $this->template->replaceTemplate('message', 'registration', $message);
        }


Messages In This Thread
DB Insert -- Insert Query Errors out but insert happens??? - by El Forum - 07-31-2008, 07:58 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.