<?php
	include 'includes/session.php';
	include 'includes/sessions.php';

	if(isset($_POST['edit'])){
		$id = $_POST['name']; 
		$wallet=$_POST['amount'];
		$currentDate = date('Y-m-d');
		$sql = "UPDATE users SET wallet = wallet+ '$wallet' WHERE name = '$id'";
		$sqltransaction = "INSERT INTO transaction_history(name,amount, dates, receiver_id,type) VALUES ('admin','$wallet','$currentDate','$id','wallet')"; 

		if($conn->query($sql) && $conn->query($sqltransaction)){
			$_SESSION['success'] = 'Wallet updated successfully';

			
		}
		else{
			$_SESSION['error'] = $conn->error;
		}
	}
	else{
		$_SESSION['error'] = 'Fill up edit form first';
	}

	header('location:add_towallet.php');

?>