connect_error) die("Connection failed: " . $conn->connect_error); $msg = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $old = sha1($_POST['old_password']); $new = sha1($_POST['new_password']); $confirm = sha1($_POST['confirm_password']); $username = $_SESSION['admin']; $res = $conn->query("SELECT * FROM admin_users WHERE username='$username' AND password='$old'"); if ($res->num_rows == 1) { if ($new === $confirm) { $conn->query("UPDATE admin_users SET password='$new' WHERE username='$username'"); $msg = "Password updated successfully!"; } else { $msg = "New passwords do not match."; } } else { $msg = "Old password is incorrect."; } } ?>