<?php
	session_start();
	include"../../connect/db.php"; 
?>
<?php

	$chap = $_SESSION['chap'];

	if( isset($_POST['oldpword']) ){

		$oldpword = mysqli_real_escape_string($con,$_POST['oldpword']);

		$sql = mysqli_query($con,"SELECT password FROM admin WHERE id = '1' ");

		$row = mysqli_fetch_assoc($sql);

		if( $oldpword == $row['password'] ){
			echo "password correct";
		}
		else{
			echo "password incorrect";
		}
	}
	else if( isset($_POST['newpword'])){

		$newpword = mysqli_real_escape_string($con,$_POST['newpword']);

		$sql = mysqli_query($con,"UPDATE admin SET password = '$newpword' WHERE id = '1' ");

		if( $sql ){
		    session_unset();
        	session_destroy();
			echo "success";
		}
		else{
			echo "error";
		}
	}
?> 