mardi 19 décembre 2017

how to store multiple check boxes with single name in one cell of the mysql data base in php.?

` ENQUIRY FORM

  <div class="row">
      <label class="col-md-3" for="zones">Zones in Bangalore</label>
      <div class="checkboxes">
        <p id="zones"><input type="checkbox" name="zones[]" class="zones">CBD 
          <input type="checkbox" name="zones[]" class="zones">North 
          <input type="checkbox" name="zones[]" class="zones">South  
          <input type="checkbox" name="zones[]" class="zones">East  
          <input type="checkbox" name="zones[]" class="zones">West</p>
      </div>
    </div>

    <div class="row">
        <label class="col-md-3" for="propertytype">Property Type</label>
        <div class="checkboxes">
          <p id="propertytype">
            <input type="checkbox" name="propertytype[]" class="propertytype">Apartment &nbsp;

            <input type="checkbox" name="propertytype[]" class="propertytype">Raw House &nbsp;

            <input type="checkbox" name="propertytype[]" class="propertytype">Villa  &nbsp;
            <input type="checkbox" name="propertytype[]" class="propertytype">Residential Plot</p>
        </div>

      </div>

$('.zones').on('change', function() {
      $('.zones').not(this).prop('checked', false);
       });
      $('.propertytype').on('change', function() {
        $('.propertytype').not(this).prop('checked', false);
      });

this is the code the script code selects only one check box. i am not able figure out how to store this check box values. i am getting error while trying to store this data. I have tried to check for if condition but not able to get the code. i have 4 more similar check boxes in my project and i have to store all the data in a single database table. can you please help me to solve the problem.

In controller:

  $numreg= '/^[7-9]{1}[0-9]{9}$/';
  $this->load->helper(array('form', 'url'));
  $this->load->library('form_validation');
 if(isset($_POST['submit'])){
       $this->form_validation->set_rules('zones[]', 'zones of Bangalore',   'required');
       $this->form_validation->set_rules('propertytype[]', 'Property type', 'required');

       }

  if ($this->form_validation->run() == TRUE)
           {
             $data_to_store = array(

               'zones'=> $_POST['zones'],
               'propertytype'=> $_POST['propertytype']

          );

       $this->db->insert('enquiry', $data_to_store);
     }`




Aucun commentaire:

Enregistrer un commentaire