<?php
session_start();
include"../inc/conn.php";

// CEK HAK AKSES DISINI

$id  		= str_replace("'","`",(isset($_SESSION['id_siswa'])) ? $_SESSION['id_siswa'] : "");

$password_lama  = str_replace("'","`",(isset($_POST['password_lama'])) ? $_POST['password_lama'] : "");
$password_baru1 = str_replace("'","`",(isset($_POST['password_baru1'])) ? $_POST['password_baru1'] : "");
$password_baru2 = str_replace("'","`",(isset($_POST['password_baru2'])) ? $_POST['password_baru2'] : "");


$cek=mysqli_query($connect,"select * from tb_siswa where id_siswa='".$id."'");
$rcek=mysqli_fetch_array($cek);



if($rcek['password']!=$password_lama){
	echo"<script>alert('Password lama salah !!!');history.go(-1)</script>";
}elseif(($password_baru1)!=($password_baru2)){
	echo"<script>alert('Password baru harus sama !!!');history.go(-1)</script>";
}else{




$update = mysqli_query($connect,"update tb_siswa set password = '".$password_baru1."' where id_siswa='".$id."'")or die(mysqli_error($connect));


if($update){
	echo"<script>alert('Password berhasil diperbarui !');history.go(-1)</script>";
	echo"<script>document.location.href='gantipassword'</script>";
}else{
	echo"<script>alert('Gagal mengeksekusi perintah ini !');history.go(-1)</script>";
}





}
?>