<?php
require_once './connection.php';

if (!isset($_POST['logout']) == "") {
    session_start();
    session_destroy();
    unset($_SESSION);
}

if (!isset($_POST['old_password']) == "" && !isset($_POST['new_password']) == "") {
//    echo 'old_password ' . $_POST['old_password'];
//    echo 'new_password ' . $_POST['new_password'];
    $old_password = $_POST['old_password'];
    $new_password = $_POST['new_password'];

    $sql = "SELECT * FROM tbl_admin_login WHERE username='jaydip' and password=" . $old_password . "";

    if ($con) {
        $result = mysqli_query($con, $sql);
        $row = mysqli_fetch_assoc($result);
        $username = $row["username"];
//        echo 'username '.$username;
        if ($username=='jaydip') {
            $sql1 = "UPDATE tbl_admin_login SET password=" . $new_password . " WHERE username='jaydip' and password=" . $old_password . "";

            if ($con->query($sql1) === TRUE) {
                echo "Record updated successfully";
            } else {
                echo "Error updating record: " . $con->error;
            }
        } else {
            echo "Old Password Not Match in Database !";
        }
    } else {
        echo 'Connection Problem';
    }

    $con->close();
}


?>