Kenapa $_session[''] selalu undefined ci 3

ini kenapa ya id_user tidak terdeteksi padahal di database saya bener primary keyny buat user itu id_user tapi kenapa tidak terdetek

ini kode buat nampilin

<!-- Begin Page Content -->
<div class="container-fluid">

    <!-- Page Heading -->
    <h1 class="h3 mb-4 text-gray-800"><?= $title; ?></h1>

    <div class="row">
        <div class="col-lg">
            <?php if (validation_errors()) : ?>
                <div class="alert alert-danger" role="alert">
                    <?= validation_errors(); ?>
                </div>

            <?php endif; ?>
            <?= $this->session->flashdata('message'); ?>

            <a href="" class="btn btn-primary mb-3" data-toggle="modal" data-target="#orderMenu">Add New Order</a>
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th scope="col">#</th>
                        <th scope="col">Nama Pelanggan</th>
                        <th scope="col">Alamat</th>
                        <th scope="col">Nama Barang</th>
                        <th scope="col">Jumlah</th>
                        <th scope="col">Tanggal Pengiriman</th>
                        <th scope="col">Status</th>

                    </tr>
                </thead>
                <tbody>
                    <?php $i = 1; ?>
                    <?php foreach ($order as $o) : ?>
                        <tr>
                            <th scope="row"><?= $i++; ?></th>
                            <td><?= $o['pelanggan']; ?></td>
                            <td><?= $o['alamat']; ?></td>
                            <td><?= $o['nama_brg']; ?></td>
                            <td><?= $o['jumlah']; ?></td>
                            <td><?= $o['tgl_kirim']; ?></td>
                            <td><?= $o['id_pelanggan']; ?></td>
                            <td><?= $o['status']; ?></td>
                            <td><a class="badge badge-success" href="<?= base_url(); ?>user/edit_order/<?= $o['id_order']; ?>">Edit</a>
                                <a class="badge badge-danger" href="<?= base_url(); ?>user/hapus_order/<?= $o['id_order']; ?>">Delete</a>
                                <a class="badge badge-primary" href="<?= base_url(); ?>user/bayar/<?= $o['id_order']; ?>">Pembayaran</a>
                            </td>

                        </tr>
                    <?php endforeach; ?>

                </tbody>
            </table>
        </div>

    </div>
    <!-- /.container-fluid -->

</div>
<!-- End of Main Content -->
<!-- Button trigger modal -->

<!-- Modal -->
<div class="modal fade" id="orderMenu" tabindex="-1" role="dialog" aria-labelledby="orderMenu" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="orderMenu">Order</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <form action="<?= base_url('user/pesanan'); ?>" method="POST">
                <div class="modal-body">
                    <div class="form-group">
                        <input type="text" class="form-control" id="pelanggan" name="pelanggan" placeholder="Nama Pelanggan">
                    </div>
                    <div class="form-group">
                        <input type="text" class="form-control" id="alamat" name="alamat" placeholder="Alamat Pelanggan">
                    </div>
                    <div class="form-group">
                        <select name="nm_barang" id="nm_barang" class="form-control">
                            <option value="">Select Menu</option>
                            <?php foreach ($nama_brg as $nm) : ?>
                                <option value="<?= $nm['id_brg']; ?>"><?= $nm['nama_brg']; ?> </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="form-group">
                        <input type="text" class="form-control" id="jumlah" name="jumlah" placeholder="Jumlah">
                    </div>
                    <div class="form-group">
                        <label>Tanggal Pengiriman<input class="form-control" type="date" name="tgl_kirim" id="tgl_kirim"></label>
                    </div>
                    <div class="form-group">
                        <input type="text" class="form-control" id="id_pelanggan" name="id_pelanggan" value="<?= $_SESSION['id_user']; ?>" readonly>
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="hidden" name="status" id="status" value="0" />
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Add</button>
                </div>
            </form>
        </div>
    </div>
</div>

ini kode functionnya saya pake CI terima kasih gan

public function pesanan()
    {
        $data['title'] = "Orderan";
        $data['user'] = $this->db->get_where('user', ['id_user' => $this->session->userdata('id_pelanggan')])->row_array();

        $data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();

        $this->load->model('ModelBarang', 'barang');
        $data['order'] = $this->barang->getPesanan();

        $data['nama_brg'] = $this->db->get('barang')->result_array();

        $this->form_validation->set_rules('pelanggan', 'Nama Anda', 'required');
        $this->form_validation->set_rules('alamat', 'Alamat', 'required');
        $this->form_validation->set_rules('nm_barang', 'Nama Barang', 'required');
        $this->form_validation->set_rules('jumlah', 'Jumlah', 'required');
        $this->form_validation->set_rules('tgl_kirim', 'Tanggal', 'required');

        if ($this->form_validation->run() == false) {
            $this->load->view('templates/header', $data);
            $this->load->view('templates/sidebar', $data);
            $this->load->view('templates/topbar', $data);
            $this->load->view('user/pesanan', $data);
            $this->load->view('templates/footer');
        } else {
            $data = [
                'id_order' => $this->input->post('id_order'),
                'pelanggan' => $this->input->post('pelanggan'),
                'alamat' => $this->input->post('alamat'),
                'nm_barang' => $this->input->post('nm_barang'),
                'jumlah' => $this->input->post('jumlah'),
                'tgl_kirim' => $this->input->post('tgl_kirim'),

                'status' => $this->input->post('status')
            ];
            $this->db->insert('order_brg', $data);
            $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">New Sub Menu Added</div>');
            redirect('user/pesanan');
        }
    }

avatar werich1
@werich1

89 Kontribusi 7 Poin

Dipost 4 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban