Welcome Guest, Not a member yet? Register   Sign In
Showing error message , need help...
#1

[eluser]Unknown[/eluser]
I am a very new learner of CI. Recently I am trying to develop a user registration system in Codeigniter. I have successfully inserted users registration data into database. If user submit user data then controller file calls this model.

My controller is user_reg.php




My model is reg_model.php

Code:
class Reg_model extends CI_Model{
    
    
    
    public function __construct()
    {
        parent::__construct();
    }
    
    public function add_user(){
        $user_name=$this->input->post('username');
        $pass=$this->input->post('pass');
        $email=$this->input->post('email');
        
        $data=array('name'      => $user_name,
                    'password'  => $pass,
                    'email'     => $email
                    );
        
        $this->db->where("name",$user_name);
        $this->db->where("password",$pass);
        
        $query=$this->db->get("reg");
        if($query->num_rows==0){
        
        $this->db->insert('reg',$data);
        }
        
    }
}

And also calls this view for letting know the user , that if his/her registration is successful or not.

com_reg.php
Code:
echo "Thanks for registration....";

But the problem is, if any user submit any data twice or more then the model will not insert this data into database. But it shows that registration is successful. If I put the error message in model then the problem could be solved, but it breaks the MVC rule.

So please give me any suggestion how to fix the problem in MVC pattern .
#2

[eluser]Samus[/eluser]
[quote author="peacehunter" date="1334138745"]I am a very new learner of CI. Recently I am trying to develop a user registration system in Codeigniter. I have successfully inserted users registration data into database. If user submit user data then controller file calls this model.

My controller is user_reg.php




My model is reg_model.php

Code:
class Reg_model extends CI_Model{
    
    
    
    public function __construct()
    {
        parent::__construct();
    }
    
    public function add_user(){
        $user_name=$this->input->post('username');
        $pass=$this->input->post('pass');
        $email=$this->input->post('email');
        
        $data=array('name'      => $user_name,
                    'password'  => $pass,
                    'email'     => $email
                    );
        
        $this->db->where("name",$user_name);
        $this->db->where("password",$pass);
        
        $query=$this->db->get("reg");
        if($query->num_rows==0){
        
        $this->db->insert('reg',$data);
        }
        
    }
}

And also calls this view for letting know the user , that if his/her registration is successful or not.

com_reg.php
Code:
echo "Thanks for registration....";

But the problem is, if any user submit any data twice or more then the model will not insert this data into database. But it shows that registration is successful. If I put the error message in model then the problem could be solved, but it breaks the MVC rule.

So please give me any suggestion how to fix the problem in MVC pattern . [/quote]

In my personal registration system, I created validation callbacks, to check if user data already exists in the DB. If it does, it simply shows an error telling the user so.

So it doesn't even get to the insert process if there are duplicate records.

Have a read about callbacks, they're very useful.

http://ellislab.com/codeigniter/user-gui...#callbacks




Theme © iAndrew 2016 - Forum software by © MyBB