Nisha
Nisha

Reputation: 158

Set flashdata is not working

I am building a simple project using codeigniter in which I want to save data into database and display a message once data is successfully inserted into database. For this I am using codeigniters set flash data but its not working. The data is saved into database successfully only the problem is its not displaying message. Below is the code I am using.

Controller:

               public function add_patient()
               {

               $this->form_validation->set_rules('fname', 'Firstname','trim|required');
               $this->form_validation->set_rules('mname', 'Middlename','trim|required');
               $this->form_validation->set_rules('lname', 'Lastname','trim|required');
               $this->form_validation->set_rules('adds', 'Address','trim|required');
               $this->form_validation->set_rules('con', 'Contact','trim|required');
               $this->form_validation->set_rules('dor', 'Contact','trim|required');
                   if($this->form_validation->run() == FALSE)
                    {
                       $this->welcome();
                    }
                   else
                   {

                        $this->load->model('addpatientM');
                        $fname1=$this->input->post('fname');
                        $lname1=$this->input->post('lname');
                        $mname1=$this->input->post('mname');
                        $age1=$this->input->post('age');
                        $adds1=$this->input->post('adds');
                        $con1=$this->input->post('con');
                        $dor1=$this->input->post('dor');
                        $gen1=$this->input->post('gen');

                       $submit = $this->addpatients>insert_patient


                   ($fname1,$lname1,$mname1,$gen1,$age1,$adds1,$con1,$dor1);

                        if ($submit >0) 
                        {
                         $this->load->library('session');
                         $this->Session->set_flashdata('success', 'successfully added');
                       }
                    $this->welcome();
                   }
                 }

View:

           <form name='frm1' action="<?php echo base_url(); ?>
           index.php/Registrationc/add_patient" role="form" id="form1" 
           method="post" enctype="multipart/form-data">
           <?php echo $this->session->flashdata('success'); ?>

           <input type="text" class="form-control" id="fname" name="fname">

           <?php echo form_error('fname');?>

          <input type="text" class="form-control" id="mname" name="mname">

          <?php echo form_error('mname');?>


          <input type="text" class="form-control" id="lname" name="lname">

          <?php echo form_error('lname');?>


          <textarea rows="4" cols="50" placeholder="Address" class="form-
          control" id="adds" name="adds"></textarea>

          <?php echo form_error('adds');?>

          <input type="text" placeholder="Age" class="form-control" id="age" 
          name="age">

          <?php echo form_error('cage');?>

          <select class="form-control" id="gen" name="gen">
          <option value="">Select Gender</option>
          <option value="Male">Male</option>
          <option value="Female">Female</option>
          <option value="Others">Others</option>
          </select>

          <?php echo form_error('gen');?>

          <input type="text" data-date-format="yyyy-mm-dd" data-date-
          viewmode="years" class="form-control date-picker" class="datepick" 
          id="dor" name="dor">

          <?php echo form_error('dor');?>       


          <input type="text" id="form-field-mask-2" class="form-control input-
           mask-phone" id="con" name="con">

           <?php echo form_error('con');?>

           <center>

           <input type="submit" value="Submit" class="btn btn-bricky" 
            id="subbtn" name="submit">
           </center>

           </form>  

Please any one help me for this. I am not understanding what is the problem. Is there anything more to add

Upvotes: 0

Views: 167

Answers (1)

Arif Sajal
Arif Sajal

Reputation: 133

you did not load the session class Into construct function , first of all load the session class globally for both view and controller.

$this->load->library('session');

Than Try to set the flashdata

$this->session->set_flashdata('key','value');

Keep in mind that session Library must be accessible from both controller and view.

Upvotes: 1

Related Questions