php - values in database not inserted in codeIgniter? -


i new php framework have created simple form , want inserts value in database failed don't know wrong!!!

every time getting mysql returned empty result set (i.e. 0 rows). using codeigniter 3 , mysqli drivers controller

<?php        //display_errors(on);        error_reporting(e_all);        class register extends ci_controller {        public function index () {        //validations        $rules=array (                  "username"=> array(                     "field"=>"username",                     "label"=>"username",                     "rules"=>"required|max_length[20]|min_length[5]|callback_username_is_taken"                   ),                  "password"=> array(                     "field"=>"password",                     "label"=>"password",                     "rules"=>"required|max_length[20]|min_length[6]"                   ),                  "pass_conf"=> array(                     "field"=>"pass_conf",                     "label"=>"password",                     "rules"=>"required|matches[password]"                   ),                 "email"=> array(                     "field"=>"email",                     "label"=>"email",                     "rules"=>"required|valid_email|callback_is_taken"                   )        );        //set rules        $this->form_validation->set_rules($rules);       //override message       $this->form_validation->set_message('required','the %s field empty');        // check see if form has been submitted       if ($this->form_validation->run()!=true) {              $this->load->helper('url');              $this->load->view('register'); //display page              $this->load->view('footer');       }else {             echo "donkey butt";              $form=array();             $form['username']=$this->input->post("username");             $form['password']=md5($this->input->post("password"));             $form['email']=$this->input->post("email");              if(self::createuser($form['username'],$form['password'],$form['email'])==true) {                      //created user                     echo "success";                     //$this->load->view("success",$data);              }else{                 echo "problem in subbmitting form";             }         }       }        public function username_is_taken($input) {                  $query="select * `tbl_usrs`  `username`=? ";             $arg=array ($input);             $exec=$this->db->query($query,$arg) or die(mysqli_error());             echo $query;              if($exec->num_rows() >0)              {                 $this->form_validation->set_message('username_is_taken','sorry username <b> $input </b> taken');                 return false;               }else {                 return true;             }        }           public function email_is_taken($input) {              $query="select * `tbl_usrs` `email`=? ";             $arg=array ($input);             $exec=$this->db->query($query,$arg) or die(mysqli_error());             echo $query;             if($exec->num_rows() >0)              {                 $this->form_validation->set_message('email_is_taken','sorry email <b> $input </b> taken');                 return false;               }else {                 return true;             }        }        public function createuser($user,$pass,$email)       {             $query="                 insert `tbl_usrs` (`username`,`password`,`email`,`ip`)                 values (?,?,?,?)              ";             $arg=array (self::protect($user),self::protect($password),$email,$_server['remote_addr']);              if($this->db->query($query,$arg)==true)             {                 echo $query;                 return true; // if added database             }else {                     return false;             }            }        public function protect($str) {             return mysqli_real_escape_string($str);       } }        ?> 

fixing mysqli_real_escape_string($str); //excepts 2 parameters 1 given fixing make code work


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -