Save data from dropdown at session and show in another page Codeigniter

Hello I have a problem using codeigniter.
Here I want to save the data selected through the dropdown into a session, then display the selected data to a page called step4. I have tried but when I display the data, it does not appear.

Here is the script:

Controller Step1.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Step1 extends CI_Controller {

  function __construct() {
    parent::__construct();
    $this->load->helper('url');
    $this->load->library('session');
    $this->load->model('M_datasiswa');
  }

    public function step1()
    {
    $data['departemen'] = $this->M_datasiswa->get_departemen();
    $data['tahunajaran'] = $this->M_datasiswa->get_tahunajaran();
        $this->load->view('v_step1',$data);
  }

  function save_data(){
    $depart = $this->input->post('kode_departemen');
    $tahun = $this->input->post('kode_tahun');
    $asal = $this->input->post('kode_asal');

    $data = array(
      'departemen' => $depart,
      'proses' => $tahun,
      'asal' => $asal
    );
    $this->session->set_userdata($data);
    redirect('step4');

    }



}

v_step1.php

<form action="<?php echo base_url('Step1/save_data'); ?>" method="post">
      <table border="0" style="text-align:left; margin-left: auto; margin-right: auto; width:97%; margin-top:50px;">
        <tr style="height:50px;">
          <td style="width:100px;"> </td>
          <td class="tulisanDalamTabel" colspan="2"> &nbsp; Departemen </td>
          <td colspan="1" style="width: 100px;"> </td>
          <td colspan="2">
            <select required name="kode_departemen" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
                <option value="" disabled diselected>--PILIH UNIT--</option>
              <?php
                foreach ($departemen as $row) { echo "<option value='".$row->replid."'>".$row->departemen."</option>";}echo"</select>"?>
          </td>
        </tr>

        <tr style="height:50px;" >
          <td style="width:100px;"></td>
          <td class="tulisanDalamTabel" colspan="2"> &nbsp; PPDB </td>
          <td colspan="1" style="width: 100px;"> </td>
          <td colspan="2">
            <select required name="kode_tahun" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
                <option value="" disabled diselected>--PILIH TAHUN AJARAN--</option>
              <?php
                foreach ($tahunajaran as $row) { echo "<option value='".$row->replid."'>".$row->proses."</option>";}echo"</select>"?>
          </td>
        </tr>

        <tr style="height:50px;">
          <td style="width:100px;"></td>
          <td class="tulisanDalamTabel" colspan="2"> &nbsp; Asal Calon Siswa </td>
          <td colspan="1" style="width: 100px;"> </td>
          <td colspan="2">
            <select required name="kode_asal" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
                <option value="" disabled diselected>--PILIH--</option>
              <option> UMUM </option>
              <option> KELUARGA YAYASAN </option>
          </td>
        </tr>

        <tr style="height:50px;">
        <td colspan="8"><hr style="width: 98%"/></td>
        </tr>
        <tr style="height:50px;">
          <td class="tulisanDalamTabel" colspan="2"><input type="submit" class="buttonKembali" value="Batal Daftar" style="vertical-align:middle"> </td>
          <td colspan="4"> </td>
          <td class="tulisanDalamTabel" style="text-align:right; width:380px"><input type="submit" class="buttonSelanjutnya" value="Selanjutnya" style="vertical-align:middle;"> </td>
        </tr>
      </table>
    </form>

v_step4.php

<table border="1" style="text-align:left; margin-left: auto; margin-right: auto; width:97%; margin-top:50px;">
        <tr style="height:50px;">
          <td class="tulisanDalamTabel"> &nbsp; Nama Lengkap </td>
          <td> <input type="text" placeholder="Nama Lengkap" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;"/> </td>
          <td> <?php $this->session->userdata('departemen') ?></td>
          <td class="tulisanDalamTabel"> &nbsp; Nama Panggilan </td>
          <td> <input type="text" placeholder="Nama Panggilan" class="tulisanDalamTabel" style="width:97%; margin-left: 1px; height:40px;"/> </td>
        </tr>

Thanks, hope someone can help me.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You forgot to print using echo

<td> <?php $this->session->userdata('departemen') ?></td>

Do this instead

<td> <?php echo $this->session->userdata('departemen') ?></td>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x