<?php

$name=$_POST['name'];
$invoice_no=$_POST['invoice_no'];
$msisdn=$_POST['msisdn'];
$invoice_date=$_POST['invoice_date'];
$amount=$_POST['amount'];
$credit_date=$_POST['credit_date'];
require_once "config.php";

$sql="select * from vendor_invoice_details where invoice_no='".$invoice_no."' and customer_name='".$name."' and status='pending'";
$query=mysqli_query($con,$sql);
if($result=mysqli_fetch_array($query)){
    die("Invoice exists");
}


$sql="insert into vendor_invoice_details(credit_date,customer_name,invoice_no,msisdn,invoice_date,amount,balance) values('".$credit_date."','".$name."','".$invoice_no."','".$msisdn."','".$invoice_date."','".$amount."','".$amount."')";
$query=mysqli_query($con,$sql);
$count=mysqli_affected_rows($con);


if($query==false){
    die(mysqli_error($con));
}
echo $count;


?>