Postingan lainnya
Ini gimana caranya ya ngebuat sistem posting berdasarkan user
gan ane bikin form posting nah ane bikin table postnya ada field namanya email_id mau ane join sama user id nah pas udh di posting gimana ya biar carany si field email_id dari table postfes ini otomatis keisi sama user id?
<h1 class="h3 mb-0 text-gray-800"><?= $title; ?></h1>
<?= $this->session->flashdata('message'); ?>
<div class="row">
<div class="col-lg">
<?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" value="<?= set_value('namaFes'); ?>">
</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="text" class="form-control" id="tempat" name="tempat" placeholder="Tempat Pelaksanaan" value="<?= set_value('tempat'); ?>">
</div>
<label>Tanggal</label>
<div class="form-group">
<input type="date" class="form-control" id="tanggal" name="tanggal" placeholder="Tanggal Festival" value="<?= set_value('tanggal'); ?>">
</div>
<label> S/d </label>
<div class="form-group">
<p>Note : Isikan dengan tanggal yang sama jika 1 hari </p>
<input type="date" class="form-control" id="tanggal2" name="tanggal2" placeholder="Tanggal Festival" value="<?= set_value('tanggal2'); ?>">
<?= form_error('tanggal2', 'Isikan dengan tanggal yang sama jika acara tidak lebih dari satu hari ---', '<small class="text-danger pl-3">', '</small>'); ?>
</div>
<div class="form-group">
<textarea style="height: 150px;" class="form-control" id="deskripsi" name="deskripsi" placeholder="Keterangan" value="<?= set_value('deskripsi'); ?>"></textarea>
</div>
<div class="form-group">
<input type="text" class="form-control" id="email_id" name="email_id" value="<?= $_SESSION['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(); ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
ini viewnya
public function addpost()
{
$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();
$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('tanggal2', 'Tanggal', 'required|trim');
$this->form_validation->set_rules('deskripsi', 'Deskripsi', 'required|trim');
$this->form_validation->set_rules('tempat', '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');
$tempat = $this->input->post('tempat');
$tanggal = $this->input->post('tanggal');
$tanggal2 = $this->input->post('tanggal2');
$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,
'tempat' => $daerah,
'tanggal' => $tanggal,
'tanggal2' => $tanggal2,
'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');
}
}
ini controllernya
public function getPostModel4()
{
$query = "SELECT `postfes`.*, `user`.`id`
FROM `postfes` JOIN `user`
ON `postfes`.`email_id` = `user`.`id`
WHERE `postfes`.`email_id` = '" . $_SESSION['id'] . "'";
return $this->db->query($query)->result_array();
}
ini modelnya mohon bantuannya gan
0
4 Jawaban:
Jawaban Terpilih
Seperti ini
<pre> $data = [ 'namaFes' => $namaFes, 'daerah_id' => $daerah, 'tempat' => $daerah, 'tanggal' => $tanggal, 'tanggal2' => $tanggal2, 'deskripsi' => $desk, 'email_id' => $this->session->userdata('user_id'), 'image' => $image ];
$this-&gt;db-&gt;insert('postfes', $data);
</pre>
0