-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCFinsert.php
31 lines (31 loc) · 1.19 KB
/
CFinsert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
$con=mysqli_connect("localhost","root","","lids");
$requestJSONData = file_get_contents('php://input');
$requestArray = json_decode($requestJSONData,true);
$licenseid=$requestArray['licenseid'];
$cf=$requestArray['cf'];
$cf=(int)$cf;
$startdate=$requestArray['startdate'];
$current = date("Y-m-d");
$days_between = floor((strtotime($current)- strtotime($startdate))/24/3600/60/60);
if($days_between==0)$days_between=1;
$cfpday=$cf / $days_between;
$expire=floor((10000 - $cf)/$cfpday);
$EstimateExpiry= date('Y-m-d', strtotime($current. ' + '.$expire.' days'));
echo $EstimateExpiry;
$stget = mysqli_query($con, "SELECT * FROM tb_pollutionquotient WHERE LicenseID= '$licenseid'");
if(mysqli_num_rows($stget)>0){
$row=mysqli_fetch_assoc($stget);
$oldcf=$row["CurrentCF"];
$updatecf=$oldcf+$cf;
$query="update tb_pollutionquotient set CurrentCF='$updatecf', EstimatedExpiry='".$EstimateExpiry."' where licenseid='$licenseid'";
$result=mysqli_query($con,$query);
echo mysqli_error($con);
}
else {
$query="insert into tb_pollutionquotient values ($licenseid,$cf,'".$startdate."','".$EstimateExpiry."',10000)";
mysqli_query($con,$query);
echo mysqli_error($con);
}
mysqli_close($con);
?>