	<?php
	/**
	* Created by PhpStorm.
	* User: ahmad
	* Date: 20/08/2019
	* Time: 11:48 AM
	*/

	require_once("../connection.php");
	
		$key=mysqli_real_escape_string($connect, $_POST['key']);
		$old_password=mysqli_real_escape_string($connect, $_POST['old_password']);
		$new_password=mysqli_real_escape_string($connect, $_POST['new_password']);


	$getusers = mysqli_query($connect,"SELECT * FROM users WHERE id_session='$key'");
	$u	      = mysqli_fetch_array($getusers);
	$jumlah   = mysqli_num_rows($getusers);

	if ($jumlah > 0){
	
    $passold=md5($old_password);
    $pass=md5($new_password);
	
	
	$passworddata = mysqli_query($connect,"SELECT * FROM users WHERE password='$passold'");
	$p=mysqli_fetch_array($passworddata);
	
	if($p['password']==$passold){
		mysqli_query($connect,"UPDATE users SET password = '$pass'
                             WHERE phone_number			 = '$u[phone_number]'");
													 
							 
	$json = array(
    'status' 		=> 'true',
    'errCode'	 	=> '01',
	'msg' 			=> 'Success'
	);

    echo json_encode($json);
	}else{
		
		
	$json = array(
    'status' 		=> 'true',
    'errCode'	 	=> '00',
	'msg' 			=> 'Your old password is wrong'
	);

    echo json_encode($json);
		
	}

	}else{
	
	$json = array(
    'status' => 'true',
    'errCode' => '00',
	'msg' => 'User Not Found'
	);

    echo json_encode($json);	
	}
	?>