Gagal membuat update password baru (error password lama tidak terbaca pada perintah query)

<?php
            $id        = @$_GET['id_user'];
            $query     = mysqli_query($koneksi,"SELECT * FROM tbl_user WHERE id_user = '$id'") or die (mysqli_error($koneksi));
            $data      = mysqli_fetch_array($query);

          ?>
              <?php
              //Proses ganti Password
                if(@$_POST['edit']){
                  $id_user       = @$_POST['id_user'];
                  $username      = @$_POST['username'];
                  $password_lama = @$_POST['password_lama'];
                  $password_baru = @$_POST['password_baru'];
                  $conf_password = @$_POST['conf_password'];

                  $sumber = @$_FILES['photo']['tmp_name'];
                  $target = '../image/';
                  $ukuran_file = $_FILES['photo']['size'];
                  $tipe_file = $_FILES['photo']['type'];
                  $photo = @$_FILES['photo']['name'];

                  //Cek Password lama
                  $query = mysqli_query($koneksi,"SELECT * FROM tbl_user WHERE username = '$username' AND password = md5('$password_lama')");
                  $hasil  = mysqli_num_rows($query);
                  var_dump($hasil);
                  if (! $hasil >= 1) {
                    ?>
                        <script language="JavaScript">alert('Password lama tidak sesuai!, silahkan ulang kembali!'); document.location='dashboard.php';
                        </script>
                    <?php
                  }

avatar arif140392
@arif140392

10 Kontribusi 0 Poin

Diperbarui 5 tahun yang lalu

Tanggapan

halo, biasakan diperjelas, tidak bisanya dimana, errornya apa, yang diharapkan apa

errornya di verifikasi password lama sama dengan data password di database

coba ditambahkan di atas keterangannya, baca "aturan main" cara bertanya yang baik, jangan hanya paste kodenya

4 Jawaban:

coba pakai

<pre> if($hasil &lt; 1 ) { // password lama tidak sesuai } </pre>

avatar uzzielpelawak
@uzzielpelawak

72 Kontribusi 21 Poin

Dipost 5 tahun yang lalu

Tanggapan

Masih belum solved

<pre> //Proses ganti Password if(@$_POST['edit']){ $id_user = @$_POST['id_user'];
$username = @$_POST['username']; $password_lama = @$_POST['password_lama']; $password_baru = @$_POST['password_baru']; $conf_password = @$_POST['conf_password'];

              $sumber = @$_FILES[&#039;photo&#039;][&#039;tmp_name&#039;];
              $target = &#039;../image/&#039;;
              $ukuran_file = $_FILES[&#039;photo&#039;][&#039;size&#039;];
              $tipe_file = $_FILES[&#039;photo&#039;][&#039;type&#039;];
              $photo = @$_FILES[&#039;photo&#039;][&#039;name&#039;];

              //Cek Password lama
              $password_lama = md5(&#039;password_lama&#039;);              
              $query = mysqli_query($koneksi,&quot;SELECT * FROM tbl_user WHERE id_user = &#039;$id_user&#039; AND password = &#039;$password_lama&#039;&quot;) or die (mysqli_error($koneksi));
              $count  = mysqli_num_rows($query);
              var_dump($count);

            if($photo == &quot;&quot;){
              if($count &amp;lt; 1){
                if(strlen($password_baru) &amp;gt;= 5){
                  if($password_baru == $conf_password){
                    $password_baru = md5($password_baru);
                    @$id_user = $_SESSION[&#039;id_user&#039;];

                          $update = mysqli_query($koneksi,&quot;UPDATE tbl_user SET password = &#039;$password_baru&#039; WHERE id_user = &#039;$id_user&#039;&quot;);
                              if($update){
                              ?&amp;gt;
                                &amp;lt;script type=&quot;text/javascript&quot;&amp;gt;alert(&quot;Password Berhasil di Ubah&quot;);
                                window.location.href=&quot;dashboard.php&quot;;&amp;lt;/script&amp;gt;
                              &amp;lt;?php
                              }else{
                              ?&amp;gt;
                                &amp;lt;div class=&quot;alert alert-danger alert-dismissible&quot; role=&quot;alert&quot;&amp;gt;
                                  Gagal Ubah Password
                                  &amp;lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&amp;gt;
                                    &amp;lt;span aria-hidden=&quot;true&quot;&amp;gt;&amp;times;&amp;lt;/span&amp;gt;
                                  &amp;lt;/button&amp;gt;
                                &amp;lt;/div&amp;gt;
                              &amp;lt;?php
                              }

                  }else{
                    ?&amp;gt;
                      &amp;lt;div class=&quot;alert alert-danger alert-dismissible&quot; role=&quot;alert&quot;&amp;gt;
                        Konfirmasi password tidak cocok
                        &amp;lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&amp;gt;
                          &amp;lt;span aria-hidden=&quot;true&quot;&amp;gt;&amp;times;&amp;lt;/span&amp;gt;
                        &amp;lt;/button&amp;gt;
                      &amp;lt;/div&amp;gt;
                    &amp;lt;?php
                  }

                }else{
                  ?&amp;gt;
                      &amp;lt;div class=&quot;alert alert-danger alert-dismissible&quot; role=&quot;alert&quot;&amp;gt;
                        Minimal Password baru adalah 5 karakter
                        &amp;lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&amp;gt;
                          &amp;lt;span aria-hidden=&quot;true&quot;&amp;gt;&amp;times;&amp;lt;/span&amp;gt;
                        &amp;lt;/button&amp;gt;
                      &amp;lt;/div&amp;gt;
                  &amp;lt;?php
                }

              }else{
                ?&amp;gt;
                    &amp;lt;div class=&quot;alert alert-danger alert-dismissible&quot; role=&quot;alert&quot;&amp;gt;
                     Password Lama Tidak Sesuai
                      &amp;lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&amp;gt;
                        &amp;lt;span aria-hidden=&quot;true&quot;&amp;gt;&amp;times;&amp;lt;/span&amp;gt;
                      &amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                  &amp;lt;?php
              }

</pre>

Udah berusaha tapi masih belum solved juga

avatar arif140392
@arif140392

10 Kontribusi 0 Poin

Dipost 5 tahun yang lalu

Kamu ubah kondisi if di bagian ini <pre> if($count &lt; 1){} //jadi if($count &gt; 0){ //your code here } </pre>

avatar bosque
@bosque

187 Kontribusi 104 Poin

Dipost 5 tahun yang lalu

coba di echo querynya, jalankan manual. berhasil atau tidak

avatar Nandar
@Nandar

648 Kontribusi 204 Poin

Dipost 5 tahun yang lalu

Login untuk ikut Jawaban