Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to store multiple checkbox values in one column in a database in cakePHP?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.53k
    Comment on it

    For storing the multiple values in the database through check box, when a user select multiple choices,that selected value will be shown in database For Example a user want to select their education in the form so it will shown in database in one column by using explode() function it will Split a string by string, so this will allow different values to the database table.

    <?php
    <input type="checkbox" value="10" name="education[]">10th
    <input type="checkbox" value="12" name="education[]">12th
    <input type="checkbox" value="btech" name="education[]">Btech
    <input type="checkbox" value="btech" name="education[]">Mtech
    <input type="checkbox" value="btech" name="education[]">phd
    ?>

    controller code:

       function register()
          {		
          
          		if($this->request->data)
                       {
    
          		        pr($this->request->data);
          			$education = $this->request->data['education'];
    
          		             $output = implode(',',$education);
          			
          			$this->request->data['education'] = $output;
    
          			$this->request->data['password'] = md5($this->request->data['password']);
    
          			if($this->User->save($this->request->data))
                                 {
          				 $this->Session->setFlash('Registration successfully!!');  
         				 $this->redirect(array('action'=>'login'));
          			     }
          			else
                                 {
          				 $this->Session->setFlash('Something went wrong!');  
         				 $this->redirect(array('action'=>'login'));
          			     }
          	
          	            }
          }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: