<?php
include('database.php');
session_start();

$id = $_SESSION['id'];
$results = mysqli_query($connection, "SELECT `date`, `id`, `name`, `email`, `number`, `password`, `phone`, `address`, `country`, `gender`, `image`, `vcode`, `verified`, `verify`, `balance`, `totalbalance`, `investbalance`, `profit`, `totaldeposit`, `totalwithdrawal`, `loanlimit`, `availableloan`, `ongoingloan`, `savings`, `idcard`, `idcardback`, `accountstatus`, `pina`, `pinb`, `pinc`, `pind` FROM users WHERE id ='$id'");
$retrive = mysqli_fetch_array($results);
$date = $retrive['date'];
$id = $retrive['id'];
$name = $retrive['name'];
$email = $retrive['email'];
$number = $retrive['number'];
$password = $retrive['password'];
$phone = $retrive['phone'];
$address = $retrive['address'];
$country = $retrive['country'];
$gender = $retrive['gender'];
$image = $retrive['image'];
$vcode = $retrive['vcode'];
$verified = $retrive['verified'];
$verify = $retrive['verify'];
$balance = $retrive['balance'];
$totalbalance = $retrive['totalbalance'];
$investbalance = $retrive['investbalance'];
$profit = $retrive['profit'];
$totaldeposit = $retrive['totaldeposit'];
$totalwithdrawal = $retrive['totalwithdrawal'];
$loanlimit = $retrive['loanlimit'];
$availableloan = $retrive['availableloan'];
$ongoingloan = $retrive['ongoingloan'];
$savings = $retrive['savings'];
$idcard = $retrive['idcard'];
$idcardback = $retrive['idcardback'];
$accountstatus = $retrive['accountstatus'];
$pina = $retrive['pina'];
$pinb = $retrive['pinb'];
$pinc = $retrive['pinc'];
$pind = $retrive['pind'];



if (isset($_POST['submit']))
	; {


	$amount = mysqli_real_escape_string($connection, $_POST['amount']);


	$rnotification = "Save";
	$rmessage = 'You save $' . $amount . ' from your Lenexbanking Balance';


	$newavalable = $savings + $amount;




	$addbalance = $balance - $amount;
	$add_query = "UPDATE users SET balance='$addbalance', savings='$newavalable' WHERE id='$id' LIMIT 1";
	$add_query_run = mysqli_query($connection, $add_query);
	if ($add_query_run) {
		$notification_query = "INSERT INTO `notifications` (`id`, `subject`, `message`) VALUES ('$id', '$rnotification', '$rmessage')";
		$notification_query_run = mysqli_query($connection, $notification_query);

		$_SESSION['status'] = 'You save $' . $amount . ' from your Lenexbanking Balance';

		header("location:../success.php");
	} else {
		$_SESSION['status'] = "Failed Try Again Later";

		header("location: ../failed.php");
	}
}


?>