Question

Register Controller...

    class Register_Controller extends My_Controller
    {
        public function __construct()
        {
            parent::__construct();

            $this->load->model('user_model', 'user');
        }


        public function registration()
     {
      $this->load->library('form_validation');

      // field name, error message, validation rules
      $this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');
      $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');

      if($this->form_validation->run() == FALSE)
      {
          echo 'form not validated';
          echo validation_errors(); 


      }
      else
      {
       echo 'adding user';
       $this->user_model->add_user();
      }
     }

User Model

<?php
    Class User_Model extends CI_Model
    {
     function login($email, $password)
     {
       $this -> db -> select('user_id, email, password, full_name');
       $this -> db -> from('users');
       $this -> db -> where('email', $email);
       $this -> db -> where('password', MD5($password));
       $this -> db -> limit(1);

       $query = $this -> db -> get();

       if($query -> num_rows() == 1)
       {
         return $query->result();
       }
       else
       {
         return false;
       }
     }

     public function add_user()
     {
         echo 'adding a user';
      $data=array(
        'email'=>$this->input->post('email'),
        'password'=>md5($this->input->post('password'))
      );
      $this->db->insert('users',$data);

     }

    }
    ?>

Login View

                <?php echo form_open('Register_Controller/registration'); ?>
                <div class="registerbox box">
                    <h3>New to Needzilla? Sign up!</h3>
                    <form action="index.php/Register_Controller/registration" class="form-horizontal">
                      <div class="control-group">
                        <div class="controls">
                          <input type="text" id="inputFullname" class="signinoptinboxemail" placeholder="Full name">
                        </div>
                      </div>
                        <div class="control-group">
                        <div class="controls">
                             <input type="text" size="20" id="email" name="email" class="signinoptinboxemail" placeholder="Email" value='<?php echo set_value('email'); ?>'/>
                        </div>
                      </div>
                      <div class="control-group">
                        <div class="controls">
                          <input type="password" size="20" id="password" name="password" class="signinoptinboxemail" placeholder="Password" value='<?php echo set_value('password'); ?>' />
                        </div>
                      </div>
                      <div class="control-group">
                        <div class="controls">
                          <input type="submit" value="Login" class="btn signupbutton"/>
                        </div>
                      </div>
                    </form>

                </div>
                 <?php echo form_close(); ?>

The output is this...

enter image description here

The Database looks like this...

enter image description here

Meaning it gets to the add_user function in the model but I don't understand where it's getting stuck... Let me know if there is other information I should provide you with!

Was it helpful?

Solution

$this->user_model->add_user(); change this line to $this->user->add_user();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top