samedi 21 décembre 2019

how to enter data according to the user who is currently logged in?

i make a table post and i have a field email_id to foreign key with user id and i make some Added posting, my question is how i can added automaticly the email_id from who the user session posting it.. i have tried 2 days and the post can be post but the email_id not automaticly get the data from who posting it..

<?php echo form_open_multipart('user/addpost'); ?>
    <div class="modal-body">
        <div class="form-group">
            <input type="text" class="form-control" id="namaFes" name="namaFes" placeholder="Nama Festival">
        </div>
        <div class="form-group">
            <select name="daerah_id" id="daerah_id" class="form-control">
                <option value="">Pilih Daerah</option>
                <?php foreach ($nm_daerah as $nm) : ?>
                    <option value="<?= $nm['id_daerah']; ?>"><?= $nm['nm_daerah']; ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <div class="form-group">
            <input type="date" class="form-control" id="tanggal" name="tanggal" placeholder="Tanggal Festival">
        </div>
        <div class="form-group">
            <textarea style="height: 80px;" class="form-control" id="deskripsi" name="deskripsi" placeholder="Keterangan"></textarea>
        </div>
        <div class="form-group">
            <input type="text" class="form-control" id="email_id" name="email_id" value="<?= $user['email']; ?>" readonly>

            <!--<div class=" form-group">
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" value="1" name="isActive" id="isActive" checked>
                    <label class="form-check-label" for="isActive">
                        Is it active?
                    </label>
                </div>
        </div>-->
            <div class="custom-file">
                <input type="file" class="custom-file-input" id="image" name="image">
                <label class="custom-file-label" for="image">Choose 1:1 image...</label>
            </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>
            <? echo form_close(); ?>

this my addedpost.php

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


    $data['nm_daerah'] = $this->db->get('daerah')->result_array();
    $data['postfes'] = $this->db->get('postfes')->row_array();
    $this->load->model('PostModel', 'post');
    $data['postFes'] = $this->post->getPostModel4();


    $this->form_validation->set_rules('namaFes', 'Nama Festival', 'required|trim');
    $this->form_validation->set_rules('daerah_id', 'Nama Daerah', 'required|trim');
    $this->form_validation->set_rules('tanggal', 'Tanggal', 'required|trim');
    $this->form_validation->set_rules('deskripsi', 'Deskripsi', 'required|trim');

    if ($this->form_validation->run() == false) {

        $this->load->view('templates/user-header', $data);
        $this->load->view('templates/user-sidebar', $data);
        $this->load->view('templates/user-topbar', $data);
        $this->load->view('user/addpost', $data);
        $this->load->view('templates/user-footer');
    } else {

        $namaFes = $this->input->post('namaFes');
        $daerah = $this->input->post('daerah_id');
        $tanggal = $this->input->post('tanggal');
        $desk = $this->input->post('deskripsi');
        $idpost = $this->input->post('email_id');
        $image = $_FILES['image'];
        if ($image = '') {
        } else {
            $config['upload_path'] = './assets/img/posting/';
            $config['allowed_types'] = 'jpg|gif|png|jpeg';

            $this->load->library('upload', $config);
            if (!$this->upload->do_upload('image')) {
                echo 'failed upload image';
                die();
            } else {
                $image = $this->upload->data('file_name');
            }
        }

        $data = [
            'namaFes' => $namaFes,
            'daerah_id' => $daerah,
            'tanggal' => $tanggal,
            'deskripsi' => $desk,
            'email_id' => $idpost,
            'image' => $image
        ];

        $this->db->insert('postfes', $data);
        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">Please wait admin approve your post</div>');
        redirect('user/addpost');
    }
}

and this my model and controller i join it




Aucun commentaire:

Enregistrer un commentaire