<?php
include('../headertop.php');
include('../db.php');
//include('../datepicker.php');

$disp = '';
$pagetitle = 'Edit Client Information';

if(!isset($_POST['editclientsubmit']))
{
echo '<meta http-equiv="refresh" content="0;URL=viewclients.php">';
exit;
}

$id = $_POST['id'];
$name = $_POST['name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$flat_no = $_POST['flat_no'];
$bank_details = $_POST['bank_details'];
$total_cost = $_POST['total_cost'];
$purchase_details = $_POST['purchase_details'];
$project = $_POST['project'];


if(empty($id) or empty($phone) or empty($address) or empty($total_cost) or empty($project))
{
$sm = '<span class="error">Please fill all required details</span>';
echo '<meta http-equiv="refresh" content="0;URL=editclient.php?sm='.$sm.'&id='.$id.'">';
exit;
}

$q = "update client set name='$name', address='$address', phone='$phone', bank_details='$bank_details', total_cost='$total_cost', purchase_details='$purchase_details', flat_no='$flat_no', project='$project' where id='$id'";

//mysqli_autocommit($dbcon, false);

$res = mysqli_query($dbcon,$q);

if(!$res)
{
$disp .= '<span class="error">Changes could not be saved: '.mysqli_error($dbcon).'</span>';
include('../template.php');
exit;
}
$sm = "Client details edited";

echo '<meta http-equiv="refresh" content="0;URL=editclient.php?sm='.$sm.'&id='.$id.'">';