Welcome Guest, Not a member yet? Register   Sign In
Form validation fails to prevent data entry to db
#2

[eluser]CroNiX[/eluser]
Because you're getting $title and $post from input::post(), which never returns NULL. They will return the value or boolean FALSE if it doesn't exist.
Quote:CodeIgniter comes with three helper functions that let you fetch POST, COOKIE or SERVER items. The main advantage of using the provided functions rather than fetching an item directly ($_POST['something']) is that the functions will check to see if the item is set and return false (boolean) if not.
However, I'm not sure why you are running validation on those fields and ALSO within your add_post(). You don't need the checking within add_post(), just move add_post() to be within your validation success statement.

Code:
if ($this->form_validation->run() == FALSE)
{
  //your failed stuff
}
else
{
  //success!  Write to DB...
  $this->load->model('private/add_post_model');
  $this->add_post_model->add_post($title, $post);

  //your other success stuff...
}
Code:
public function add_post($title, $post) {

        //if ($title!=NULL && $post!=NULL){  //NOT NEEDED because this was done in validation
       // $uid = $this->_get_userid();  //get current logged in user id from db
        $this->db->set('title', $title);
        $this->db->set('post', $post);
       // $this->db->set('user_id', $uid); // e.g. username = 'administrator'
        $this->db->set('user_id',  $this->session->userdata('id')); // e.g. username = 'administrator'

        $query = $this->db->insert('posts');
       // }
    }


Messages In This Thread
Form validation fails to prevent data entry to db - by El Forum - 04-28-2013, 08:06 PM
Form validation fails to prevent data entry to db - by El Forum - 04-28-2013, 08:57 PM
Form validation fails to prevent data entry to db - by El Forum - 04-28-2013, 09:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB