[eluser]ggoforth[/eluser]
I'm totally perplexed with this one. I'm trying to implement a very simple captcha for a web form I'm designing. When the blog post page loads, it generates a captcha, and saves it in the database. For some reason, It's inserting two records (two different captcha's), but the CI profiler only shows one insert query being run on the page. Any ideas? Code is below:
My controller that initiates the captcha creation
Code:
public function index($blog_id = NULL,$add_comment = false){
if(!is_null($blog_id)){
//are we adding a comment?
if($add_comment){
if($this->_validate_comments()){
//add the comments
$this->_add_comment($blog_id);
}else{
$view_data['validation_errors'] = $this->validation_errors;
}
}else{
//we are not adding comments
$this->_captcha_code();
}
//view data
$view_data['blog_object'] = $this->blog_model->get_blog_entry($blog_id);
$view_data['comment_object'] = $this->comment_model->select_comments($blog_id);
$view_data['captcha_code'] = $this->captcha_code;
//load the article view
$data['view'] = $this->load->view('article_view',$view_data,true);
$data['page_title'] = $view_data['blog_object']->blog_title;
//load the view
$this->load->view('default_layout',$data);
}else{
redirect('home');
}
//enable the profiler
$this->output->enable_profiler(TRUE);
}
So if we are not adding a comment, a captcha is generated. The captcha function is below:
Code:
private function _captcha_code(){
//generate the captcha code
$code = md5(uniqid(rand(), true));
$this->captcha_code = substr($code, 0, 7);
//save the captcha
$this->blog_model->save_captcha($this->captcha_code,$this->input->ip_address());
}
And the blog_model save captcha function - THIS IS WHERE THE TWO INSERTS ARE HAPPENING:
Code:
public function save_captcha($captcha = NULL,$ip = NULL){
//delete any existing captchas
$this->db->where('ip_address',$ip);
$this->db->delete('captcha');
//save the captcha
$arr = array('ip_address'=>$ip,'word'=>$captcha);
$this->db->insert('captcha',$arr);
}
There are no loops, and even the profiler only shows the one insert....yet I get two records each time the page loads....
Very bizarre.