Welcome Guest, Not a member yet? Register   Sign In
problems in insert checkbox value and corresponding text value.
#1

I want to insert multiple checkbox value and corresponding textbox value in to database. some times its working well most of the time the textbox value inserted as 0
i try lot of method . 
input form
Code:
checkbox
<input type = "checkbox" id="mycheck1" name="certid[]">
<input type = "checkbox" id="mycheck2" name="certid[]">
<input type = "checkbox" id="mycheck3" name="certid[]">
<input type = "checkbox" id="mycheck4" name="certid[]">
<input type = "checkbox" id="mycheck5" name="certid[]">

textitem
<input type="text"  name="noc1[]" id="eprimaryincome1" size="2" value="850"  >
<input type="text"  name="noc1[]" id="eprimaryincome2" size="2" value="300"  >
<input type="text"  name="noc1[]" id="eprimaryincome3" size="2" value="300"  >
<input type="text"  name="noc1[]" id="eprimaryincome4" size="2" value="300"  >
<input type="text"  name="noc1[]" id="eprimaryincome5" size="2" value="300"  >
method 1
Code:
$date = new DateTime("now");
 $today = $date->format('Y-m-d');
   $Specilized_category = $this->input->post('certid');
   $amt = $this->input->post('txt');
   $data=array('appno' =>$appno,'regno' =>$regno ,
   'certid'=>json_encode(implode(",", $Specilized_category)),
    'noc' => 1 ,
    'date' => $today ,
    'amt' => $amt
);
$this->db->insert('appdet', $data);

method 2
Code:
$certid = $this->input->post('certid');
 $count = count($certid);
 $amt = $this->input->post('txt',TRUE);
 $date = new DateTime("now");
 $today = $date->format('Y-m-d');
 $noc=1;
 $data =array();
 for($i=0; $i<$count; $i++) {
 $data[$i] = array(
          'appno' => $appno,
          'regno' => $regno,
          'certid' => $certid[$i],
          'noc' => $noc,
          'date'=> $today,
          'amt'=>$amt[$i]

          );
method 3
Code:
if(isset($_POST['certid']) && $_POST['certid']!="")
{
 

 $certids = $this->input->post('certid');  //here you leave the [ ] out!
 $nocs = $this->input->post('noc1');
 //print_r($nocs);
 $amtt = $this->input->post('txt');  

  $field1_array = isset($_POST['certid']) ? $_POST['certid'] : array();
   $field2_array = isset($_POST['noc1']) ? $_POST['noc1'] : array();
   $field3_array = isset($_POST['txt']) ? $_POST['txt'] : array();

   $total_rows = count($field1_array);

   if ($total_rows > 0)
   {
       for ($i=0; $i<$total_rows; $i++)
       {
       $field1_val = $field1_array[$i];
       $field2_val = $field2_array[$i];
       $field3_val = $field3_array[$i];

       $date = new DateTime("now");
 $today = $date->format('Y-m-d');

        $insert = array();
       $insert[] = array(
         'appno' => $appno,
         'regno' => $regno,
          'certid' => $field1_val,
             'noc' => 1,
             'date' => $today,
             'amt' => $field3_val
               );      
     
       $this->load->model('user_Model');
       $this->User_Model->studreginsert($insert);            
       }
   }
method 4
Code:
$certids = $this->input->post('certid');  //here you leave the [ ] out!
$nocs = $this->input->post('noc');
$nocs = isset($_POST['noc'][$i]) ? 1 : 0;
$result = array();

foreach ($certids as $index=>$certid) {
  $result[] = $certid . '_' . $nocs[$index];
}

$date = new DateTime("now");
    $today = $date->format('Y-m-d');

foreach($result as $value)
       {
       list($certid,$noc) = explode ('_',$value);
        $insert = array();
       $insert[] = array(
           'appno' => $appno,
           'regno' => $regno,
          'certid' => $certid,
             'noc' => $noc,
             'date' => $today
               );      
all methods working well but some times. that amt inserted as '0'. 
Code:
$value = $this->input->post('formvalue', TRUE);
this can also be not worked. Kindly help me to solve my problem .

Attached Files Thumbnail(s)
   
Reply


Messages In This Thread
problems in insert checkbox value and corresponding text value. - by kvanaraj - 04-13-2019, 05:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB