Postingan lainnya
Ganti Password berhasil diubah tetapi di database tidak berubah
<?php
include 'koneksi.php';
session_start();
$query = "SELECT * FROM user;";
$sql = mysqli_query($conn, $query);
$no = 0;
$result = mysqli_fetch_assoc($sql);
$username = $result['username'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--bootstrap -->
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="css/bootstrap.min.css" rel="stylesheet" >
<script src="js/bootstrap.bundle.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--font-->
<link rel="stylesheet" href="./fontawesome/css/font-awesome.min.css">
<!-- Data Tables -->
<!-- datatable style -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">
<!-- jquery -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<title>Aplication LOI</title>
</head>
<div class="container-fluid">
<div class="card">
<div class="card-header"><strong>Pengaturan Akun</strong></div>
<div class="card-body">
<form action="" method="POST">
<div class="form-group w-25">
<input type="text" name="username" class="form-control" value="<?php echo $_SESSION['username']; ?>" readonly>
</div>
<div class="form-group w-25">
<label>Password Baru</label>
<input type="text" name="pass" class="form-control" placeholder="Masukkan Password Baru" required autofocus>
</div>
<div class="form-group w-25">
<label>Konfirmasi Password Baru</label>
<input type="text" name="konfirmasi_password" class="form-control" placeholder="Konfirmasi Password Baru" required>
</div>
<button type="submit" name="submit" class="btn btn-primary">Update</button>
<a href="../dashboard.php" name="" class="btn btn-danger">Back</a>
</form>
<?php
if(isset($_POST['submit'])) {
$username = $_POST['username'];
$password = md5($_POST['pass']);
$pass = $_POST['pass'];
$konfirmasi_password = $_POST['konfirmasi_password'];
$id_user_login = $_SESSION['username'];
if($pass == $konfirmasi_password) {
//echo "Password Sesuai";
//echo $id_user_login;
$password_md5 = md5($pass);
//mysqli_query($query, "UPDATE user SET pass='$pass' WHERE id_user=$id_user_login");
//echo "<script>alert('Berhasil Diubah!'); window.location = '../dashboard.php'</script>";
$query = "UPDATE user SET pass='pass' WHERE username=$id_user_login";
$sql = mysqli_query($conn, $query);
echo "<script>alert('Berhasil Diubah!'); window.location = '../dashboard.php'</script>";
} else {
echo "<script>alert('Password tidak Sesuai!'); window.location = './profil.php'</script>";
}
}
?>
</div>
</div>
</div>
</html>
1 Jawaban:
<div>Perubahan password berhasil dilakukan, tetapi tidak diperbarui di database karena Anda menggunakan username alih-alih id_user dalam kueri UPDATE.<br><br>Kode yang benar seharusnya:<br><br><br></div><pre>$query = "UPDATE user SET pass='$pass' WHERE id_user=$id_user_login"; $sql = mysqli_query($conn, $query); echo "<script>alert('Berhasil Diubah!'); window.location = '../dashboard.php'</script>";</pre><div><br><br>Mohon gantikan baris berikut:<br><br><br></div><pre>$query = "UPDATE user SET pass='pass' WHERE username=$id_user_login";</pre><div><br><br>Dengan baris ini:<br><br><br></div><pre>$query = "UPDATE user SET pass='$pass' WHERE id_user=$id_user_login";</pre><div><br><br>Setelah Anda melakukan perubahan tersebut, silakan coba lagi dan beri tahu saya apakah masalahnya telah teratasi.</div>