<?php 
include_once('IsLogined.php');
$username = $_SESSION['admin'];
$oldpw    = $_POST["oldpw"];
$newpw    = $_POST['newpw'];
if(empty($oldpw) || empty($newpw)){
	echo("<script language=javascript>alert('填写不完整!');window.history.go(-1);</script>");
	exit();
}
include_once("../config/databaseConfig.inc.php");
$sql = "SELECT * FROM Admin WHERE username = '{$username}' and password = '{$oldpw}'"; 
# 从数据库中查询出资料集
$rs = $db->GetRow($sql); # 执行查询，并取得一个空的资料集
if (!$rs) {
	echo("<script language=javascript>alert('修改失败!原始密码不正确');window.location = 'Admin_Index_Main.php' </script>");
	exit;
}

$updateSQL = "update Admin set `password` = '{$newpw}' where `username` = '{$username}'";
$db->Execute($updateSQL); 
$db->close();
echo("<script language=javascript>alert('修改成功!');window.location = 'Admin_Index_Main.php' </script>");
exit;
?>