Sunday, 17 August 2014

Simple Registration form using codeigniter

Posted by D. arunkumar  |  13 comments




 CREATE TABLE IF NOT EXISTS `clist` (  
  `sno` int(11) NOT NULL AUTO_INCREMENT,  
  `name` varchar(55) NOT NULL,  
  `email` varchar(55) NOT NULL,  
  `password` varchar(55) NOT NULL,  
  `city` varchar(55) NOT NULL,  
  PRIMARY KEY (`sno`)  
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;  
 


  autoload.php :   
 We have to change in autoload.php as follows,  
  $autoload['libraries'] = array('database','form_validation','uri');   
  $autoload['helper'] = array('html', 'form', 'url');   

 register_view.php:  
 <style type="text/css">  
 table {  
      background:#ADDAF1;  
      border-radius:10px;  
      margin-top:95px;  
 }  
 </style>  
 <title><?php echo $title;?></title>  
 <form action="http://justcourse.site40.net/index.php/controllername/methodname/" name="form1" id="form1" method="post" >  
 <table width="200" border="0" align="center">  
  <tr>  
   <td>Name:</td>  
   <td><input type="text" name="name" id="name"> <font color="#FF0000"><?php echo form_error('name');?></font></td>  
  </tr>  
  <tr>  
   <td>Email:</td>  
   <td><input type="text" name="email" id="email"> <font color="#FF0000"><?php echo form_error('email');?></font></td>  
  </tr>  
  <tr>  
   <td>Password:</td>  
   <td><input type="password" name="password" id="password"> <font color="#FF0000"><?php echo form_error('password');?></font></td>  
  </tr>  
  <tr>  
   <td>City:</td>  
   <td><select name="city" id="city">  
   <option value="">Select</option>  
   <option value="bangalore">bangalore</option>  
   <option value="vijayawada">vijayawada</option>  
   </select> <font color="#FF0000"><?php echo form_error('city');?></font></td>  
  </tr>  
  <tr><td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="Register"></td></tr>  
 </table>  
 </form>  

 Controller(register.php)  
 <?php  
 class register extends CI_Controller {  
      public function __construct(){  
           parent::__construct();  
           $this->load->model("register_model");  
      }       
      public function index()  
      {  
      $this->insert();       
      }  
      public function insert()  
      {  
           $this->form_validation->set_rules('name', 'Name', 'required');  
           $this->form_validation->set_rules('email', 'Email', 'required');  
           $this->form_validation->set_rules('password', 'Password', 'required|numeric');  
           $this->form_validation->set_rules('city','City','required');  
           if ($this->form_validation->run())  
           {       
           $register=$this->register_model->insertdata($_POST);  
           if($register){  
                     echo "<script>alert('added Sucessfully')</script>";  
                }  
           }  
           $data['title']="Registration";  
        $this->load->view('register_view',$data);       
      }  
 }  
 ?>  

 Model(register_model.php):  
 <?php  
 class register_model extends CI_Model {  
      function insertdata($options = array()){  
           if(isset($options['name']))  
                $this->db->set('name',strip_tags($options['name']));  
                if(isset($options['email']))  
                $this->db->set('email',strip_tags($options['email']));  
           if(isset($options['password']))  
                $this->db->set('password',strip_tags($options['password']));  
           if(isset($options['city']))  
                $this->db->set('city',($options['city']));  
                $this->db->insert("clist");  
           return $this->db->insert_id();  
      }  
 }  
 ?>  

02:36 Share:

13 comments:

  1. thanks sir give more example in codeignitor

    ReplyDelete
  2. Sure rohit..i will update more modules.......

    ReplyDelete
  3. sir its not working.....i have tried it n ci 3 bt it is not working

    ReplyDelete
    Replies
    1. please follow instruction as given. It will work.

      Delete
  4. sir it works bt doesn't go to next page im new to code igniter so i have little problems....im trying and thanks a lot sir @@@@@@im felling happy you can mail me at abhishekkashyap092@gmail.com

    ReplyDelete
  5. thanks a lot sir ,now i'm going to create a login for this could you help me for this

    ReplyDelete
    Replies
    1. Please Share Your Requirement ,So that we will work For your Requirement kashyap.....

      Delete
  6. how to add the pay-pal in codeigniter

    ReplyDelete
  7. hello sir after using this code
    "An Error Was Encountered
    Unable to load the requested class: Uri "
    this error will be come, please give me solution .

    ReplyDelete
    Replies
    1. in auto load page you want change this:
      $autoload['libraries'] = array('database','form_validation','uri');
      to
      $autoload['libraries'] = array('database','form_validation');

      Delete
  8. Thank You i understand this but i need a simple way but it work i tried it.

    ReplyDelete
  9. sir its not working after submitting....alert message is not displaying...and data is not stored in DB

    ReplyDelete
    Replies
    1. Hi What Error your are Getting,mention here.....

      Delete

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top