Foreach error

Ini codingnya

userlist.php

contoh gambar userlist

Foreach masih bisa

Tapi saat saya klik edit muncul kyk gini

itu knp ya kok bisa gitu? Padahal di userlist variabel usernya bisa, tpi pas klik edit malah variabel user tidak terdefinisi, Mohon bantuannya

avatar novan1
@novan1

16 Kontribusi 1 Poin

Diperbarui 6 tahun yang lalu

6 Jawaban:

isi dari id_user nya ada ga gan? coba di die dump deh.., terus itu kenapa ga ter highlight,, bisa jadi masalah qoute nya gan..

avatar reihanagamsk
@reihanagamsk

125 Kontribusi 41 Poin

Dipost 6 tahun yang lalu

@reihanagamsk

ada isinya, soalnya di delete id nya masih bisa, tapi saat klik edit malah error, di die dump masih gk bisa, apa nya yg gk terhighlight?

avatar novan1
@novan1

16 Kontribusi 1 Poin

Dipost 6 tahun yang lalu

hmm,, brrti bkn karena qoute, kirain saya yg terhighlight <pre> '' . $row-&gt;id_user </pre> disini,, mslhnya ga ke render semestinya, brrti klo di delete bisa bkn disitiu mslhmya.. coba di cek controller atau pass ngoper data ke bagian hlmn edit gan,, mungkin agan lupa passing data variable $user nya..

avatar reihanagamsk
@reihanagamsk

125 Kontribusi 41 Poin

Dipost 6 tahun yang lalu

controller edit sama delete

function edit

<pre> public function edit($id = null) { if ($this-&gt;input-&gt;post('submit')) {

  $this-&amp;gt;form_validation-&amp;gt;set_rules(&#039;password&#039;, &#039;Password&#039;, &#039;required|min_length[5]&#039;);

  $this-&amp;gt;form_validation-&amp;gt;set_rules(&#039;level&#039;, &#039;Level&#039;, &#039;required|in_list[admin,member]&#039;);

  $this-&amp;gt;form_validation-&amp;gt;set_message(&#039;required&#039;, &#039;%s tidak boleh kosong!&#039;);
  $this-&amp;gt;form_validation-&amp;gt;set_message(&#039;min_length&#039;, &#039;%s minimal %d karakter!&#039;);

  if ($this-&amp;gt;form_validation-&amp;gt;run() === TRUE) {

    $data = array(
      &#039;password&#039; =&amp;gt; password_hash($this-&amp;gt;input-&amp;gt;post(&#039;password&#039;), PASSWORD_DEFAULT),
      &#039;level&#039; =&amp;gt; $this-&amp;gt;input-&amp;gt;post(&#039;level&#039;),
    );

    $query = $this-&amp;gt;User_model-&amp;gt;update($id, $data);

    if ($query) $message = array(&#039;status&#039; =&amp;gt; true, &#039;message&#039; =&amp;gt; &#039;Berhasil memperbarui user&#039;);
    else $message = array(&#039;status&#039; =&amp;gt; true, &#039;message&#039; =&amp;gt; &#039;Gagal memperbarui user&#039;);

    $this-&amp;gt;session-&amp;gt;set_flashdata(&#039;message&#039;, $message);

    redirect(&#039;user/edit/&#039;.$id, &#039;refresh&#039;);
  } 
}

$user = $this-&amp;gt;User_model-&amp;gt;get_where(array(&#039;id_user&#039; =&amp;gt; $id))-&amp;gt;row();

if (!$user) show_404();

$data[&#039;pageTitle&#039;] = &#039;Edit Data User&#039;;
$data[&#039;username&#039;] = $user;
$data[&#039;pageContent&#039;] = $this-&amp;gt;load-&amp;gt;view(&#039;user/useredit&#039;, $data, TRUE);

$this-&amp;gt;load-&amp;gt;view(&#039;user/userlist&#039;, $data);

} </pre>

function hapus

<pre> public function delete($id) { $user = $this-&gt;User_model-&gt;get_where(array('id_user' =&gt; $id))-&gt;row();

if (!$user) show_404();

$query = $this-&amp;gt;User_model-&amp;gt;delete($id);

if ($query) $message = array(&#039;status&#039; =&amp;gt; true, &#039;message&#039; =&amp;gt; &#039;Berhasil menghapus user&#039;);
else $message = array(&#039;status&#039; =&amp;gt; true, &#039;message&#039; =&amp;gt; &#039;Gagal menghapus user&#039;);

$this-&amp;gt;session-&amp;gt;set_flashdata(&#039;message&#039;, $message);

redirect(&#039;user&#039;, &#039;refresh&#039;);

} } </pre>

apanya yg salah? bengung gue, padahal di function edit sudah ada <pre> $user = $this-&gt;User_model-&gt;get_where(array('id_user' =&gt; $id))-&gt;row(); </pre>

avatar novan1
@novan1

16 Kontribusi 1 Poin

Dipost 6 tahun yang lalu

Coba ganti variable user sama data

avatar bosque
@bosque

187 Kontribusi 104 Poin

Dipost 6 tahun yang lalu

sama aja, undefined variable : data

avatar novan1
@novan1

16 Kontribusi 1 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban