Haloo! Selamat Datang di Komunitas Private Training Web Development (61356 Members, 697 Products, 4742 Topic, 12274 Comments)

Butuh karyawan baru? atau seorang Web Developer (Part-time/Freelance/Full-time), cari disini : Members Area Jobs!

Trying to access array offset on value of type null

Dibuat
Login Terakhir 15 Hari lalu,
Telah Dilihat 75 Kali
Bagusti Muspratama Mengatakan : Premium
  1. Assalamualaikum Warahmatullahi Wabarakatuh... mohon bantuannya kakak-kakak, jadi saya mau menampilkan data dari database tapi muncul pesan error Trying to access array offset on value of type null. Kira-kira itu kesalahannya apa ya? Terimakasih
  2.  
  3. Controller saya :
  4. <?php public function change_profile()
  5. {
  6. helper(['form', 'url']);
  7. $userModel = new UserModel();
  8.  
  9. if ($this->request->getMethod() == 'post') {
  10. $rules = [
  11. 'nama' => 'required|alpha_space|min_length[2]',
  12. 'nip' => 'required|min_length[2]',
  13. ];
  14.  
  15. if ($this->validate($rules)) {
  16. $params = [
  17. 'nama' => $userModel->escapeString(esc($this->request->getPost('nama'))),
  18. 'nip' => $userModel->escapeString(esc($this->request->getPost('nip'))),
  19.  
  20. ];
  21.  
  22. $user = $userModel->where('email', session()->get('email'))
  23. ->first();
  24.  
  25. $update = $userModel->update($user['id_user'], $params);
  26.  
  27. if ($update) {
  28. session()->setFlashdata('success', 'Berhasil Update Profile. Apabila Tampilan Data Belum Berubah, Silakan Lakukan Logout dan Login Kembali');
  29. return redirect()->route('admin/user/change_profile');
  30. } else {
  31. session()->setFlashdata('danger', 'Gagal edit data');
  32. return redirect()->route('admin/user/change_profile')->withInput();
  33. }
  34. } else {
  35. $data['validation'] = $this->validator;
  36. }
  37. }
  38.  
  39. $data['title'] = 'Edit Biodata';
  40. $data['user'] = $userModel->where('id_user')->first();
  41.  
  42. return view('admin/users/profile', $data);
  43. } ?>
  44.  
  45. View Saya :
  46. <?php <form action="<?= base_url('admin/user/change_profile') ?>" method="POST" enctype="multipart/form-data">
  47. <?= csrf_field(); ?>
  48. <form>
  49. <div class="form-row">
  50. <div class="form-group col-md-6">
  51. <label for="nama"><font face="Arial" size="2">Nama</font></label>
  52. <input type="text" class="form-control" name="nama" id="nama" value="<? $user['nama'] ?>" >
  53. </div>
  54.  
  55. <div class="form-group col-md-6">
  56. <label for="nip"><font face="Arial" size="2">NIP</font></label>
  57. <input type="number" class="form-control" name="nip" id="nip" value="<?= $user['nip'] ?>" >
  58. </div>
  59.  
  60. </div>
  61. <input type="submit" value="Update" class="btn btn-info"/>
  62.  
  63. </form>
  64. </form>
  65. ?>
Ada 1 File Kiriman :
1. Screenshot_221.png (32 KB)
Maaf, Untuk Memberikan Komentar Anda Harus Login !!!