<?php include("config.php");



$dresult=mysql_query("select * from cost WHERE id='$_POST[id]' limit 1");

$drow=mysql_fetch_array($dresult);



mysql_query("delete from bank_widrow WHERE id='$drow[chid]'");





$cdate=dtformat($_POST[cdate]);

$a=substr("$cdate",0,4);

$b=substr("$cdate",5,2);

$dt=$a.$b;



$r = mysql_query("SHOW TABLE STATUS LIKE 'bank_widrow' ");

$row = mysql_fetch_array($r);

$auto_increment = $row['Auto_increment'];

	

mysql_query("update cost set cost_type='$_POST[cost_type]',pt='$_POST[pt]',amount='$_POST[amount]',cdate='$cdate',comments='$_POST[comments]',dt='$dt' ,voucher='$_POST[voucher]' , pay_methode='$_POST[pay_methode]', chid='$auto_increment' WHERE id='$_POST[id]'");





if($_POST[pay_methode] == 'Paid By'){



/*$yresult=mysql_query("select * from bill WHERE id='$_POST[id]'");

$yrow=mysql_fetch_array($yresult);*/



$cdate=dtformat($_POST[chdate]);

$a=substr("$cdate",0,4);

$b=substr("$cdate",5,2);

$dt=$a.$b;



mysql_query("insert into bank_widrow(acc_no, chackno ,amount ,cdate ,wto,comments ,dt )VALUES('$_POST[acc_no]','$_POST[chackno]', '$_POST[amount]', '$cdate','$_POST[wto]', '$_POST[comments]', '$dt')");



}

header("location:add_cost.php");

?>