<?php 
require_once 'config.php';
$error=false;
$errors=array();
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $user_id=$_GET['user_id'];
	$flyer_id=$_GET['flyer_id'];
	 $action=$_GET['action'];
	 $result = mysqli_query($con, "SELECT * FROM `settings`");
$row = mysqli_fetch_assoc($result);
 $credits=$row['credit_value'];
 	 $result1 = mysqli_query($con, "SELECT * FROM `credit_logs` where user_id='".$user_id."' AND flyer_id = '".$flyer_id."' AND DATE(created_at)='".date('Y-m-d')."'");
 	 
 	 $rowcount=mysqli_num_rows($result1);
 	 if($rowcount<1){
	 $createCustomer=mysqli_query($con,"INSERT INTO credit_logs (user_id,flyer_id,action,credits,created_at) VALUES('".$user_id."','".$flyer_id."','".$action."','".$credits."','".date('Y-m-d H:i:s')."')");
	 
	 if($createCustomer){
	     	$errors['success']='credit updated';
	 }else{
	     $errors['success']='Somthing went wrong !!';
	 }
 	 }else{
 	     $errors['success']='You already earn for today !!';
 	 }
	 	echo json_encode($errors);
}