Hallo! Selamat Datang di Marketplace produk digital, Freelancer terbaik di indonesia (69101 Members, 786 Products, 4716 Topic, 13113 Comments)

Menampilkan Notifikasi saat Menginputkan Data Yang Sama

Dibuat
Login Terakhir 22 Jam lalu,
Telah Dilihat 4610 Kali
Lawumedia Indonesia Mengatakan : Sultan Account
  1. Assalamualaikum mas.
  2. Saya ada masalah saat input data yang sama tetapi masih bisa input.
  3. Mohon bantuannya mas kalau inputkan NIP sama seharusnya ada notif gagal itu gimana ya?
  4.  
  5. ---------------------------------------- Model ---------------------------------------------
  6. <?php
  7.  
  8. function addpegawai($data){
  9. $this->db->insert('pegawai',$data);
  10. }
  11.  
  12. ?>
  13. --------------------------------------- Controller -----------------------------------------
  14. <?php
  15.  
  16. function tambah_pegawai(){
  17. $this->cek_admin();
  18. $data['title'] = 'Halaman Tambah Pegawai';
  19. $data['password'] = $this->Model_pegawai->password();
  20. $this->template->load('admin/template','admin/mod_pegawai/tambah_pegawai', $data);
  21. }
  22.  
  23. function input_pegawai(){
  24. $this->cek_admin();
  25. $nmfile = "PEGAWAI_RSSP_".time();
  26. $config['upload_path']='./assets/foto_pegawai/';
  27. $config['allowed_types']='jpg|jpeg|png';
  28. $config['file_name'] = $nmfile;
  29. $config['max_size'] = '1000'; // kb
  30. $this->load->library('upload', $config);
  31. $this->upload->do_upload('foto');
  32. $hasil=$this->upload->data();
  33.  
  34. $data = array(
  35. 'nip' => $this->input->post('nip'),
  36. 'password' => sha1($this->input->post('password')),
  37. 'nama_lengkap' => $this->input->post('nama_lengkap'),
  38. 'foto' => $hasil['file_name'],
  39. 'tmp_lahir' => $this->input->post('tmp_lahir'),
  40. 'tgl_lahir' => date_format(date_create($this->input->post('tgl_lahir')), 'Y-m-d'),
  41. 'jns_kelamin' => $this->input->post('jns_kelamin'),
  42. 'agama' => $this->input->post('agama'),
  43. 'gol_darah' => $this->input->post('gol_darah'),
  44. 'status_nikah' => $this->input->post('status_nikah'),
  45. 'pstatus' => $this->input->post('pstatus'),
  46. 'blokir' => $this->input->post('blokir'),
  47. 'alamat' => $this->input->post('alamat'),
  48. 'provinsi' => $this->input->post('provinsi'),
  49. 'kodepos' => $this->input->post('kodepos'),
  50. 'email' => $this->input->post('email'),
  51. 'no_tlp' => $this->input->post('no_tlp')
  52. );
  53.  
  54. $this->Model_pegawai->addpegawai($data);
  55.  
  56. if ($data>=1) {
  57. $this->session->set_flashdata('message',
  58. '<div class="alert alert-warning alert-dismissible" role="alert">
  59. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
  60. Data Berhasil di Tambah...!!!
  61. </div>'
  62. );
  63. redirect('administrator/tampil_pegawai','refresh');
  64. }
  65. else {
  66. $this->session->set_flashdata('message',
  67. '<div class="alert alert-warning alert-dismissible" role="alert">
  68. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
  69. Mohon Maaf NIP sudah Terdaftar...!!!
  70. </div>'
  71. );
  72. redirect('administrator/tambah_pegawai','refresh');
  73. }
  74. }
  75.  
  76. ?>
Ada 1 File Kiriman :
1. pegawai.PNG (87 KB)

Ada 1 Jawaban

PHPMU.COM Support
commented on 17 Jan 2018 07:27:23
  1. Assalam, Cuma salah sedikit pada function input_pegawai()
  2. perlu di perbaiki pada aksi input pegawai menjadi seperti berikut :
  3.  
  4. <?php
  5. function input_pegawai(){
  6. $cek = $this->db->query("SELECT * FROM pegawai where nip='".$this->input->post('nip')."'")->num_rows();
  7. if ($cek<=0) {
  8. $this->cek_admin();
  9. $nmfile = "PEGAWAI_RSSP_".time();
  10. $config['upload_path']='./assets/foto_pegawai/';
  11. $config['allowed_types']='jpg|jpeg|png';
  12. $config['file_name'] = $nmfile;
  13. $config['max_size'] = '1000'; // kb
  14. $this->load->library('upload', $config);
  15. $this->upload->do_upload('foto');
  16. $hasil=$this->upload->data();
  17.  
  18. $data = array(
  19. 'nip' => $this->input->post('nip'),
  20. 'password' => sha1($this->input->post('password')),
  21. 'nama_lengkap' => $this->input->post('nama_lengkap'),
  22. 'foto' => $hasil['file_name'],
  23. 'tmp_lahir' => $this->input->post('tmp_lahir'),
  24. 'tgl_lahir' => date_format(date_create($this->input->post('tgl_lahir')), 'Y-m-d'),
  25. 'jns_kelamin' => $this->input->post('jns_kelamin'),
  26. 'agama' => $this->input->post('agama'),
  27. 'gol_darah' => $this->input->post('gol_darah'),
  28. 'status_nikah' => $this->input->post('status_nikah'),
  29. 'pstatus' => $this->input->post('pstatus'),
  30. 'blokir' => $this->input->post('blokir'),
  31. 'alamat' => $this->input->post('alamat'),
  32. 'provinsi' => $this->input->post('provinsi'),
  33. 'kodepos' => $this->input->post('kodepos'),
  34. 'email' => $this->input->post('email'),
  35. 'no_tlp' => $this->input->post('no_tlp')
  36. );
  37. $this->Model_pegawai->addpegawai($data);
  38.  
  39. $this->session->set_flashdata('message',
  40. '<div class="alert alert-warning alert-dismissible" role="alert">
  41. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
  42. Data Berhasil di Tambah...!!!
  43. </div>');
  44. redirect('administrator/tampil_pegawai','refresh');
  45. }else {
  46. $this->session->set_flashdata('message',
  47. '<div class="alert alert-warning alert-dismissible" role="alert">
  48. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
  49. Mohon Maaf NIP sudah Terdaftar...!!!
  50. </div>');
  51. redirect('administrator/tambah_pegawai','refresh');
  52. }
  53. }
  54. ?>
  55.  
  56. Bisa dilihat untuk aksi insertnya tempatkan didalam kondisi jika if ($cek<=0)
  57. jadi jika data nip belum ada di database maka insert, jika sudah ada maka akan muncul notifikasi
  58. "Mohon Maaf NIP sudah Terdaftar...!!!", semoga bermanfaat,..
Maaf, Untuk Memberikan Komentar Anda Harus Login !!!

Online