apa sebab error di update data (CRUD)?

public function edit($id)
    {

        $data = array(
            'judul'     => 'Detail Data Penduduk',
            'penduduk'  => $this->Penduduk_model->get_penduduk_id($id),
            // 'id'        => $id,
        );

        $this->form_validation->set_rules('nama', 'Nama', 'required');
        $this->form_validation->set_rules('nik', 'NIK', 'required|numeric');
        $this->form_validation->set_rules('nomor_wa', 'Nomor WA', 'required|numeric');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('layanan', 'Layanan', 'required');

        if ($this->form_validation->run() == FALSE) {
            $this->load->view('templates/header', $data);
            $this->load->view('penduduk/ubah_penduduk', $data);
            $this->load->view('templates/footer');
        } else {
            $this->Penduduk_model->editdatapenduduk();
            $this->session->set_flashdata('flash', 'Data penduduk berhasil diubah');
            redirect('penduduk');
        }
    }

avatar nblfbrn
@nblfbrn

6 Kontribusi 0 Poin

Diperbarui 3 tahun yang lalu

Tanggapan

cara bertanyanya di rapikan ya, pasang pertanyaan di bagian pertanyaan (bisa kamu edit), jangan di jawaban, lalu jelaskan masing masing kodenya, dan dibagian mana yang error

iya kak.. lain kali jika saya bertanya lagi, pertanyaannya akan saya rapikan maap kak, tpi belom tau cara ngeditnya

4 Jawaban:

<div>Model<br><br></div><pre>public function get_penduduk_id($id) { return $this-&gt;db-&gt;get_where('tb_penduduk', ['id' =&gt; $id])-&gt;row(); }

public function editdatapenduduk()
{
    $data = [
        &quot;nama&quot;     =&amp;gt; $this-&amp;gt;input-&amp;gt;post(&#039;nama&#039;, true),
        &quot;nik&quot;      =&amp;gt; $this-&amp;gt;input-&amp;gt;post(&#039;nik&#039;, true),
        &quot;nomor_wa&quot; =&amp;gt; $this-&amp;gt;input-&amp;gt;post(&#039;nomor_wa&#039;, true),
        &quot;email&quot;    =&amp;gt; $this-&amp;gt;input-&amp;gt;post(&#039;email&#039;, true),
        &quot;layanan&quot;  =&amp;gt; $this-&amp;gt;input-&amp;gt;post(&#039;layanan&#039;, true),
    ];

    $this-&amp;gt;db-&amp;gt;where(&#039;id&#039;, $this-&amp;gt;input-&amp;gt;post(&#039;id&#039;));
    $this-&amp;gt;db-&amp;gt;update(&#039;tb_penduduk&#039;, $data);
}&lt;/pre&gt;
avatar nblfbrn
@nblfbrn

6 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

<div>view ubah_penduduk.php<br><br></div><pre>&lt;div class="container"&gt;

&amp;lt;div class=&quot;row mt-3&quot;&amp;gt;
    &amp;lt;div class=&quot;col-md-6&quot;&amp;gt;

        &amp;lt;div class=&quot;card&quot;&amp;gt;
            &amp;lt;div class=&quot;card-header&quot;&amp;gt;
                Form Edit Data Mahasiswa
            &amp;lt;/div&amp;gt;
            &amp;lt;div class=&quot;card-body&quot;&amp;gt;

                &amp;lt;form action=&quot;&amp;lt;?php echo base_url() . &#039;penduduk/edit&#039;; ?&amp;gt;&quot; method=&quot;post&quot;&amp;gt;
                    &amp;lt;input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;&amp;lt;?= $penduduk-&amp;gt;id ?&amp;gt;&quot;&amp;gt;
                    &amp;lt;div class=&quot;mb-3&quot;&amp;gt;
                        &amp;lt;label for=&quot;nama&quot;&amp;gt;Nama&amp;lt;/label&amp;gt;
                        &amp;lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;nama&quot; value=&quot;&amp;lt;?= $penduduk-&amp;gt;nama ?&amp;gt;&quot;&amp;gt;
                    &amp;lt;/div&amp;gt;

                    &amp;lt;div class=&quot;mb-3&quot;&amp;gt;
                        &amp;lt;label for=&quot;nik&quot;&amp;gt;NRP&amp;lt;/label&amp;gt;
                        &amp;lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;nik&quot; value=&quot;&amp;lt;?= $penduduk-&amp;gt;nik ?&amp;gt;&quot;&amp;gt;
                    &amp;lt;/div&amp;gt;

                    &amp;lt;div class=&quot;mb-3&quot;&amp;gt;
                        &amp;lt;label for=&quot;email&quot;&amp;gt;Email&amp;lt;/label&amp;gt;
                        &amp;lt;input type=&quot;email&quot; class=&quot;form-control&quot; name=&quot;email&quot; value=&quot;&amp;lt;?= $penduduk-&amp;gt;email ?&amp;gt;&quot;&amp;gt;
                    &amp;lt;/div&amp;gt;

                    &amp;lt;div class=&quot;mb-3&quot;&amp;gt;
                        &amp;lt;label for=&quot;layanan&quot;&amp;gt;Layanan&amp;lt;/label&amp;gt;
                        &amp;lt;br&amp;gt;
                        &amp;lt;input type=&quot;radio&quot; name=&quot;layanan&quot; value=&quot;ktp&quot; &amp;lt;?php echo ($penduduk-&amp;gt;layanan == &#039;ktp&#039; ? &#039; checked&#039; : &#039;&#039;); ?&amp;gt;&amp;gt;
                        &amp;lt;label for=&quot;ktp&quot;&amp;gt; KTP-el&amp;lt;/label&amp;gt;
                        &amp;lt;br&amp;gt;
                        &amp;lt;input type=&quot;radio&quot; name=&quot;layanan&quot; value=&quot;kia&quot; &amp;lt;?php echo ($penduduk-&amp;gt;layanan == &#039;kia&#039; ? &#039; checked&#039; : &#039;&#039;); ?&amp;gt;&amp;gt;
                        &amp;lt;label for=&quot;kia&quot;&amp;gt; Kartu Identitas Anak (KIA)&amp;lt;/label&amp;gt;
                        &amp;lt;br&amp;gt;
                        &amp;lt;input type=&quot;radio&quot; name=&quot;layanan&quot; value=&quot;kk&quot; &amp;lt;?php echo ($penduduk-&amp;gt;layanan == &#039;kk&#039; ? &#039; checked&#039; : &#039;&#039;); ?&amp;gt;&amp;gt;
                        &amp;lt;label for=&quot;kk&quot;&amp;gt; Kartu Kelurga&amp;lt;/label&amp;gt;
                        &amp;lt;br&amp;gt;
                        &amp;lt;input type=&quot;radio&quot; name=&quot;layanan&quot; value=&quot;skpwni&quot; &amp;lt;?php echo ($penduduk-&amp;gt;layanan == &#039;skpwni&#039; ? &#039; checked&#039; : &#039;&#039;); ?&amp;gt;&amp;gt;
                        &amp;lt;label for=&quot;skpwni&quot;&amp;gt; Surat Pindah (SKPWNI)&amp;lt;/label&amp;gt;
                        &amp;lt;br&amp;gt;
                        &amp;lt;input type=&quot;radio&quot; name=&quot;layanan&quot; value=&quot;perubahan&quot; &amp;lt;?php echo ($penduduk-&amp;gt;layanan == &#039;perubahan&#039; ? &#039; checked&#039; : &#039;&#039;); ?&amp;gt;&amp;gt;
                        &amp;lt;label for=&quot;perubahan&quot;&amp;gt; Perubahan Data&amp;lt;/label&amp;gt;
                        &amp;lt;br&amp;gt;
                    &amp;lt;/div&amp;gt;

                    &amp;lt;div class=&quot;text-left mt-3 mb-3&quot;&amp;gt;
                        &amp;lt;a href=&quot;&amp;lt;?php echo base_url(&#039;penduduk&#039;) ?&amp;gt;&quot; class=&quot;btn btn-info&quot;&amp;gt; &amp;lt;i class=&quot;fas fa-reply&quot;&amp;gt;&amp;lt;/i&amp;gt; Kembali &amp;lt;/a&amp;gt;
                        &amp;lt;button type=&quot;submit&quot; name=&quot;edit&quot; class=&quot;btn btn-primary&quot; float-right&amp;gt;Ubah Data&amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/form&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&lt;/div&gt;</pre>

avatar nblfbrn
@nblfbrn

6 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

<div>sesudah menekan tombol edit<br><br></div><pre><strong>An uncaught Exception was encountered</strong> Type: ArgumentCountError Message: Too few arguments to function Penduduk::edit(), 0 passed in C:\xampp\htdocs\ci-app\system\core\CodeIgniter.php on line 532 and exactly 1 expected Filename: C:\xampp\htdocs\ci-app\application\controllers\Penduduk.php Line Number: 40 Backtrace: File: C:\xampp\htdocs\ci-app\index.php Line: 315 Function: require_once</pre>

avatar nblfbrn
@nblfbrn

6 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

<div>Saya coba bantu jawab ya,<br>method edit di Controller kamu membutuhkan 1 parameter untuk menyimpan nilai id, sedangkan kamu di attribute action-nya yg mengarahkan ke controller edit, ngga nge-passing (menyertakan) id, maka nya error.<br><br>Controller</div><pre> public function edit($id) &lt;--- ada parameter $id {

    $data = array(
        &#039;judul&#039;     =&amp;gt; &#039;Detail Data Penduduk&#039;,
        &#039;penduduk&#039;  =&amp;gt; $this-&amp;gt;Penduduk_model-&amp;gt;get_penduduk_id($id),
        &lt;em&gt;// &#039;id&#039;        =&amp;gt; $id,&lt;/em&gt;
    );
    .....
}&lt;/pre&gt;&lt;div&gt;Tapi disini ngga masukkin id-nya :&lt;/div&gt;&lt;pre&gt;&amp;lt;form action=&quot;&amp;lt;?php echo base_url() . &#039;penduduk/edit&#039;; ?&amp;gt;&quot; method=&quot;post&quot;&amp;gt;&lt;/pre&gt;&lt;div&gt;&lt;br&gt;Solusinya, ubah jadi gini :&lt;/div&gt;&lt;pre&gt;&amp;lt;form action=&quot;&amp;lt;?php echo base_url() . &#039;penduduk/edit/&#039; . $penduduk-&amp;gt;id; ?&amp;gt;&quot; method=&quot;post&quot;&amp;gt;&lt;/pre&gt;&lt;div&gt;&lt;br&gt;Silahkan ganti seperti diatas dan semoga berhasil.&lt;/div&gt;
avatar ahanafi
@ahanafi

815 Kontribusi 554 Poin

Dipost 3 tahun yang lalu

Tanggapan

udah aku tambahin id di form action ny kak.. pesan errornya ga muncul lagi tpi pas di klik tombol ubah, data yg diubah kembali ke data semula trus tampilannya tetap menampilkan view dari edit.. di cek di database juga ga brubah.. itu kenapa lagi ya kak? soalnya ga muncul pesan error atau apa

Login untuk ikut Jawaban