Hi, can you guys give me tips or code snippets how handle the attempted duplicate entries in db ?
here’s my controller code
public function create_member()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email','Email Address','trim|required|valid_email');
$this->form_validation->set_rules('username','Username','trim|required|min_length[6]|max_length[16]');
$this->form_validation->set_rules('passwd','Password','trim|required|min_length[6]|max_length[16]');
$this->form_validation->set_rules('passwd2','Password Confirm','trim|required|matches[passwd]');
if($this->form_validation->run() == FALSE )
{
$data['title'] = 'Register';
$data['main_content'] = "register_view";
$this->load->view('includes/template',$data);
}
else
{
$this->load->model('member_model');
if($query = $this->member_model->create_member())
{
$data['title'] = 'Welcome';
$data['main_content'] = 'successful_view';
$this->load->view('includes/template',$data);
}
else
{
$data['title'] = 'please register!';
$data['main_content'] = 'register_view';
$this->load->view('includes/template',$data);
}
}
}
here’s my model function
public function create_member()
{
$data = array(
'email' => $this->input->post('email'),
'username' => $this->input->post('username'),
'passwd' => sha1($this->input->post('passwd'))
);
$insert = $this->db->insert('user',$data);
return $insert;
}
here’s the error am getting, it doesn’t look good coz the table columns appear LOL
A Database Error Occurred
Error Number: 1062
Duplicate entry 'testing' for key 'PRIMARY'
INSERT INTO `user` (`email`, `username`, `passwd`) VALUES ('test@gmail.com', 'testing', 'a4cac82164ef67d9d07d379b5d5d8c4abe1exxxxx')
