Postingan lainnya
cara menyimpan pemanggilan session pada form kedalam database
permisi mau tanya kalau misalnya saya melakukan pemanggilan session pada form bagaimana caranya agar session tersebut dapat tersimpan dalam database ya ?
controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Pesan extends CI_Controller { function __construct(){ parent::__construct(); $this->load->helper('url','form'); $this->load->library(array('template','templatem','session')); $this->load->library('session'); $this->load->model("pesan_model"); $this->load->model("products_model"); //jika belum login redirect ke login }
public function index() {
$data['listPesan'] = $this->pesan_model->getAllPesan(); $this->template->display('pesan/pesan_view', $data); }
public function addPesan() { $a= $data['mobil']=$this->products_model->getProduct($this->input->get('id'))->result(); $this->templatem->display('pesan/add_pesan_view',$data); }
public function addPesanDb() {
$data = array( 'id_member'=>$this->session->userdata('nama_lengkap'), 'no' => $this->input->post('no'), 'harga' => $this->input->post('harga'), 'no_hp' => $this->input->post('no_hp'), 'email' => $this->session->userdata('email'), 'tgl_pesan' => $this->input->post('tgl_pesan'), 'jam_pesan' => $this->input->post('jam_pesan'), 'tujuan' => $this->input->post('tujuan'), 'lama_sewa' => $this->input->post('lama_sewa') );
$this->pesan_model->addPesan($data); redirect('homemember'); }
public function submit(){ $this->load->helper(array('form', 'url')); $this->load->library('email'); $id_pesan=$this->input->get('id'); $config['charset'] = 'utf-8'; $config['useragent'] = 'Codeigniter'; $config['protocol']= "smtp"; $config['mailtype']= "html"; $config['smtp_host']= "ssl://smtp.gmail.com";//pengaturan smtp $config['smtp_port']= "465"; $config['smtp_timeout']= "400"; $config['smtp_user']= "pratiwianggi453@gmail.com"; // isi dengan email kamu $config['smtp_pass']= "terserah453"; // isi dengan password kamu $config['crlf']="\r\n"; $config['newline']="\r\n"; $config['wordwrap'] = TRUE; //memanggil library email dan set konfigurasi untuk pengiriman email
$this->email->initialize($config); //konfigurasi pengiriman $this->email->from($config['smtp_user']); $this->email->to($this->session->userdata('email')); $this->email->subject("Detail Pembayaran"); $this->email->message( "Halo Terimakasih telah melakukan Pemesanan di Surya Rentak Bali Silahkan melakukan pembayaran sesuai dengan data berikut<br><br>". site_url("detailpesan/index/?id=$id_pesan") );
if($this->email->send()) { $url=base_url("index.php/pesan"); echo "<script type='text/javascript'>alert('Berhasil mengirim data pemesanan !'); window.location='$url'; </script>"; }else { echo "<script type='text/javascript'>alert('Gagal mengirim silahkan Cek Koneksi Anda !'); window.location='index'; </script>"; } } }
Model
<?php class Pesan_model extends CI_Model{
function getAllPesan() { $this->db->select('pemesanan.*,daftar.*,mobil.*'); $this->db->join('daftar','daftar.id_member=pemesanan.id_member'); $this->db->join('mobil','mobil.no=pemesanan.no'); $this->db->from("pemesanan"); return $this->db->get(); }
function addPesan($data) {
$this->db->insert('pemesanan', $data);
}
function deletePesan($id) { //delete produk berdasarkan id $this->db->where('id_pesan', $id); $this->db->delete('pemesanan'); }
}
view
<h1>Form Pemesanan <small>Mobil</small><BR> </h1> </div> <form method="post" action="<?= base_url() ?>index.php/pesan/addPesanDb">
<tr> <td>Nama Lengkap </td> <td> <?php echo $this->session->userdata('nama_lengkap') ?> </td> </tr><br> <tr> <td>Nama Mobil </td> <td><input type="hidden" placeholder="Nama" name="no" size="20" value="<?php echo $mobil[0]->no; ?>" readonly="true" /> <input type="text" placeholder="Nama" name="nama" size="20" value="<?php echo $mobil[0]->nama; ?>" readonly="true" /> </td> </td> </tr><br><br>
<tr> <td>Harga</td> <td><input type="text" placeholder="Harga" name="harga" size="20" value="<?php echo $mobil[0]->harga; ?>" readonly="true" /> </td> </tr><br><br>
<tr> <td>No Hp </td> <td> <input type="text" placeholder="No Hp" name="no_hp" size="20" /> </td> </tr><br><br>
<tr> <td>Email </td> <td> <?php echo $this->session->userdata('email') ?> </td> </tr><br><br>
<tr> <td>Tanggal Pesan <td><input type="date" placeholder="Tanggal Pesan" name="tgl_pesan" size="20" /> </td> </tr><br><br>
<tr> <td>Jam Pesan <td> <input type="time" placeholder="Jam Pesan" name="jam_pesan" size="20" /> </td> </tr><br><br>
<tr> <td>Alamat <td><input type="text" placeholder="Alamat" name="tujuan" size="20" /> </td> </tr><br><br>
<tr> <td>Lama Sewa <td><input type="text" placeholder="Lama Sewa" name="lama_sewa" size="20" /> </td> </tr><br><br>
</table> <input type="submit" value="Kirim" />
1 Jawaban:
Bisa pakai <pre> $this->session->userdata('apa'); </pre> atau <pre> session_id(); </pre>