<?php include "layouts/menu.php"; ?>
<script>
	function autocomplet() {
	var min_length = 0; // min caracters to display the autocomplete
	var keyword = $('#did').val();
	if (keyword.length >= min_length) {
		$.ajax({
			url: 'ajax_area.php',
			type: 'POST',
			data: {keyword:keyword},
			success:function(data){
				$('#country_list_id').show();
				$('#country_list_id').html(data);
			}
		});
	} else {
		$('#country_list_id').hide();
	}
}
function set_item(item) {
	// change input value
	$('#did').val(item);
	// hide proposition list
	$('#country_list_id').hide();
}
	</script>
	 <script>
	function autocompa() {
	var min_length = 0; // min caracters to display the autocomplete
	var keyword = $('#didna').val();
	if (keyword.length >= min_length) {
		$.ajax({
			url: 'ajax_color.php',
			type: 'POST',
			data: {keyword:keyword},
			success:function(data){
				$('#dnamea').show();
				$('#dnamea').html(data);
			}
		});
	} else {
		$('#dnamea').hide();
	}
}

// set_item : this function will be executed when we select an item
function set_itemm(item) {
	// change input value
	$('#didna').val(item);
	// hide proposition list
	$('#dnamea').hide();
}
	</script>
 <script>
	function autocomplett() {
	var min_length = 0; // min caracters to display the autocomplete
	var keyword = $('#zxcvb').val();
	if (keyword.length >= min_length) {
		$.ajax({
			url: 'ajax_refreshvname.php',
			type: 'POST',
			data: {keyword:keyword},
			success:function(data){
				$('#qwertyu').show();
				$('#qwertyu').html(data);
			}
		});
	} else {
		$('#qwertyu').hide();
	}
}
// set_item : this function will be executed when we select an item
function set_itemmm(item) {
	// change input value
	$('#zxcvb').val(item);
	// hide proposition list
	$('#qwertyu').hide();
}
	</script>
 <script>
function add3()
{
var x = document.getElementById("hp1").value;
var y = document.getElementById("bba").value;
document.getElementById("1").value =(x*1)+(y*1);
}
</script>
<script>
function interr() {
    // Get the loan amount
    var loanAmount = parseFloat(document.getElementById("hp1").value); 
    
    // Get the interest rate (entered in percentage, e.g., 20)
    var interestRate = parseFloat(document.getElementById("5555").value);
    var y = (interestRate*1)/(12);
document.getElementById("intt2").value = (y).toFixed(2);
    // Get the due weeks
    var dueWeeks = parseFloat(document.getElementById("duemnt3").value);
    
    // Calculate the principle part: (loanAmount * interestRate) / dueWeeks
    var principlePart = (loanAmount * (interestRate / 100)) / dueWeeks;
    
    // Calculate the interest part (using the same calculation you mentioned)
    var interestPart = loanAmount * (interestRate / 100) / 12; 
    
    // Set the values in the respective fields
    document.getElementById("txt1").value = principlePart.toFixed(2); // Principle part
    document.getElementById("txt2").value = interestPart.toFixed(2); // Interest part
    
    // Calculate total due amount (principle part + interest part)
    var totalDueAmount = principlePart + interestPart;
    document.getElementById("tot").value = totalDueAmount.toFixed(2);
    
    add1(); // Call to add1 function
}
</script>

 <script>
function ddd()
{
var x = document.getElementById("hpdate").value;
document.getElementById("hpdate2").value = x;
}
</script>

 <script>
function add11()
{
var x = document.getElementById("44").value;
var y = document.getElementById("33").value;
document.getElementById("hp1").value =(x*1)+(y*1);
}
</script>
  <script>
function add()
{
var x = document.getElementById("txt1").value;
var y = document.getElementById("txt2").value;
document.getElementById("tot").value =(x*1)+(y*1);
}
</script>
  <script>
function down()
{
var x = document.getElementById("vval").value;
var y = document.getElementById("downn").value;
document.getElementById("44").value =(x*1)-(y*1);
document.getElementById("hp1").value =(x*1)-(y*1);
document.getElementById("netp").value =(x*1)-(y*1);
}
function deall()
{
var x = document.getElementById("hp1").value;

var z = document.getElementById("gfjghgf").value;
document.getElementById("netp").value =(x*1)-(z*1);
}
function dchange()
{
var x = 1; //or whatever offset
var CurrentDate = document.getElementById("hpdate").value;
document.getElementById("hpdate2").value = CurrentDate.setMonth(CurrentDate.getMonth() + x);
}
</script>
<script>
function add1()
{
var x1 = document.getElementById("hp1").value;
var y1 = document.getElementById("intt2").value;
var g = (x1*1)*(y1/100);
document.getElementById("txt2").value =Math.round(g);
//var y = (x*1)/(12);
//document.getElementById("2").value =Math.round(y);
}
</script>
<script>
function add2()
{
    calculateTotalDues();
var x1 = document.getElementById("hp1").value;
var y1 = document.getElementById("duemnt3").value;
document.getElementById("txt1").value =parseInt((x1*1)/(y1*1));
var x = document.getElementById("txt1").value;
var y = document.getElementById("txt2").value;
document.getElementById("tot").value =(x*1)+(y*1);
var z22 = document.getElementById("tot").value;
// var c = (z22*0.3/100);
// document.getElementById("defamt").value =Math.round(c);

    
    
}

function due()
{
var x = document.getElementById("txt1").value;
var y = document.getElementById("tot").value;
document.getElementById("txt2").value =(y*1)-(x*1);
}

function ddate()
{
	
	var x = 1; //or whatever offset
var CurrentDate = document.getElementById("hpdate").value;
document.getElementById("hpdate2").value = CurrentDate.setMonth(CurrentDate.getMonth() + x);
}
function allq() {
    var loanAmount = parseFloat(document.getElementById("44").value) || 0;  
    var interestRate = parseFloat(document.getElementById("intt2").value) || 0;

    var y = loanAmount * 0.03;
    var interestAmount = loanAmount * (interestRate / 100);
    var principalAfterInterest = loanAmount - interestAmount;

    document.getElementById("hp1").value = principalAfterInterest;
    document.getElementById("duemnt3").value = 100;

    var principal = parseFloat(document.getElementById("hp1").value) || 0;
    var balance = loanAmount - principal;
    var monthlyDues = parseFloat(document.getElementById("duemnt3").value) || 1;
document.getElementById("preinc").value = parseInt(loanAmount - principal);
    document.getElementById("txt1").value = parseInt(loanAmount / monthlyDues);
    document.getElementById("txt2").value = 0;
    document.getElementById("tot").value = parseInt(document.getElementById("txt1").value) + parseInt(document.getElementById("txt2").value);

    
    var agentPercentage = parseFloat(document.getElementById("dealeramt").value);  
    var commission = (loanAmount * agentPercentage) / 100;
    
    
    document.getElementById("txtgh3").value = commission.toFixed(0);
}
function uch()
{
    //alert("came");
var email=$("#email").val();// value in field email
$.ajax({
    type:'post',
        url:'checkmail.php',// put your real file name 
        data:{email: email},
        success:function(msg){
        alert(msg); // your message will come here.     
        } 
 });

}



navigator.geolocation.getCurrentPosition();
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;

if (e.keyCode == 37)
   e.preventDefault();
   
</script>
<script>
$('body').on('keydown', 'input, select, textarea', function(e) {
    var self = $(this)
      , form = self.parents('form:eq(0)')
      , focusable
      , next
      ;
    if (e.keyCode == 13) {
        focusable = form.find('input,a,select,button,textarea').filter(':visible');
        next = focusable.eq(focusable.index(this)+1);
        if (next.length) {
            next.focus();
        } else {
            form.submit();
        }
        return false;
    }
});
</script>
<script>
$('body').on('keydown', 'input, select, textarea', function(e) {
    var self = $(this)
      , form = self.parents('form:eq(0)')
      , focusable
      , next
      ;
    if (e.keyCode == 13) {
        focusable = form.find('input,a,select,button,textarea').filter(':visible');
        next = focusable.eq(focusable.index(this)+1);
        if (next.length) {
            next.focus();
        } else {
            form.submit();
        }
        return false;
    }
});
</script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).on("keypress", "input", function(e){
        if(e.which == 13){
         event.stopPropagation();
        event.preventDefault();
        $(this).next("input").focus();
        }
    }); 
    
    function getUsers(searchKey) {

    $.ajax({
        url: 'getUserm.php',
        type: 'POST',
        dataType: 'json',
        data: {value: searchKey},
        success: function(data) {
            if(data.status) {
                $("#name").val(data.userData.name);
                $("#fname").val(data.userData.fname);
				$("#address").val(data.userData.address);
				$("#address1").val(data.userData.address1);
				$("#address2").val(data.userData.address2);
				$("#lmark").val(data.userData.lmark);
				$("#pnoresi").val(data.userData.pnoresi);
				$("#gg1").val(data.userData.gg1);
					$("#img01").val(data.userData.uimg);
            } else {
                // Some code to run when nothing is found
            }   
        }
    });   

}

$(function() { // wait until to DOM is ready
var searchTimeout; //Timer to wait a little before fetching the data
$("#pno").keyup(function() {
    searchKey = this.value;

    clearTimeout(searchTimeout);

    searchTimeout = setTimeout(function() {
        getUsers(searchKey);    
    }, 400); //If the key isn't pressed 400 ms, we fetch the data
});
});
    </script>
  <!--  page-wrapper -->
         <div class="right_col" role="main">
      <h5 class="page-header  alert alert-danger">New Registration For Weekly  Loan</h5>   
            <div class="row">
                <div class="col-lg-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        
                        <div class="panel-body">
                          
                               
                                 <?php
								   $idd=$_REQUEST['id'];
								   $qry=mysqli_query($conn, "select * from customerdetailsw where id='$idd'");
						$n=mysqli_num_rows($qry);
						$row = mysqli_fetch_array($qry);
						 ?>
						
  <form role="form" name="form1" id="form1" method="post" action="" enctype="multipart/form-data">
<div class="row">

  <!-- ================= Member Details ================= -->
  <div class="col-lg-12">
    <h3 style="background:#f5f5f5;padding:10px;border-radius:5px;">Member Details</h3>
  </div>

  <div class="col-lg-4">
    <div class="form-group has-success has-feedback">
      <label>Member ID <font color="red">*</font></label>
      <input type="text" class="form-control" name="hpl" 
             value="<?php echo isset($row['hpl']) ? $row['hpl'] : ''; ?>" placeholder="E.g 1008" required>
      <input type="hidden" class="form-control" name="hplt" value="<?php echo isset($row['hplt']) ? $row['hplt'] : ''; ?>">
      <input type="hidden" class="form-control" name="mfin" value="<?php echo $mfin; ?>">
      <input type="hidden" class="form-control" name="scode" value="<?php echo $scode; ?>">
      <input type="hidden" class="form-control" name="idd" value="<?php echo $idd; ?>">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Member Name <font color="red">*</font></label>
      <input style="text-transform:uppercase" type="text" class="form-control" name="name" id="name"
             value="<?php echo isset($row['name']) ? $row['name'] : ''; ?>" onkeyup="autocomp()" placeholder="Name">
      <ul id="dname"></ul>
    </div>

    <div class="form-group has-success has-feedback">
      <label>Mobile Number <font color="red">*</font></label>
      <input type="text" class="form-control" name="pno" 
             value="<?php echo isset($row['pno']) ? $row['pno'] : ''; ?>" placeholder="Eg: 9876543210">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Father's Name</label>
      <input type="text" class="form-control" name="fname" 
             value="<?php echo isset($row['fname']) ? $row['fname'] : ''; ?>" placeholder="Name">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Father Phone No</label>
      <input type="text" class="form-control" name="pnoresi1" 
             value="<?php echo isset($row['pnoresi1']) ? $row['pnoresi1'] : ''; ?>" placeholder="Eg: 9876543210">
    </div>
  </div>

  <div class="col-lg-4">
    <div class="form-group has-success has-feedback">
      <label>Address</label>
      <input type="text" class="form-control" name="address" 
             value="<?php echo isset($row['address']) ? $row['address'] : ''; ?>" placeholder="Line 1">
      <input type="text" class="form-control" name="address1" 
             value="<?php echo isset($row['address1']) ? $row['address1'] : ''; ?>" placeholder="Line 2">
      <input type="text" class="form-control" name="address2" 
             value="<?php echo isset($row['address2']) ? $row['address2'] : ''; ?>" placeholder="Line 3 + Pincode">
    </div>

    <div class="form-group has-success has-feedback">
      <label>House Own/Rent</label>
      <select class="form-control" name="houserent">
        <option>Select</option>
        <option <?php echo (isset($row['houserent']) && $row['houserent']=="Own House") ? "selected" : ""; ?>>Own House</option>
        <option <?php echo (isset($row['houserent']) && $row['houserent']=="Own by Family Member") ? "selected" : ""; ?>>Own by Family Member</option>
        <option <?php echo (isset($row['houserent']) && $row['houserent']=="Rent House") ? "selected" : ""; ?>>Rent House</option>
        <option <?php echo (isset($row['houserent']) && $row['houserent']=="Hostel/Mansion") ? "selected" : ""; ?>>Hostel/Mansion</option>
      </select>
    </div>

    <div class="form-group has-success has-feedback">
      <label>Date</label>
      <input type="date" class="form-control" name="rdate" 
             value="<?php echo isset($row['rdate']) ? $row['rdate'] : ''; ?>">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Area <font color="red">*</font></label>
      <select class="form-control" name="area">
        <option></option>
        <?php
          $sql11 = mysqli_query($conn, "SELECT * FROM msarea ORDER BY name ASC");
          while($row11 = mysqli_fetch_array($sql11)) {
            $selected = (isset($row['area']) && $row['area']==$row11['name']) ? "selected" : "";
            echo "<option $selected>".$row11['name']."</option>";
          }
        ?>
      </select>
    </div>
  </div>

  <div class="col-lg-4">
    <div class="form-group has-success has-feedback">
      <label>Govt ID <font color="red">*</font></label>
      <input type="text" class="form-control" name="gg1" 
             value="<?php echo isset($row['gg1']) ? $row['gg1'] : ''; ?>" placeholder="Govt ID No">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Attachment 1</label>
      <input type="file" class="form-control" name="upp1">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Govt ID (Alternate)</label>
      <input type="text" class="form-control" name="g2" 
             value="<?php echo isset($row['g2']) ? $row['g2'] : ''; ?>" placeholder="Govt ID No">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Attachment 2</label>
      <input type="file" class="form-control" name="upp2">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Land Mark</label>
      <input type="text" class="form-control" name="lmark" 
             value="<?php echo isset($row['lmark']) ? $row['lmark'] : ''; ?>">
    </div>
  </div>

  <!-- ================= Loan Details ================= -->
  <div class="col-lg-12">
    <h3 style="background:#f5f5f5;padding:10px;border-radius:5px;">Loan Details</h3>
  </div>

  <div class="col-lg-4">
    <div class="form-group has-error has-feedback">
      <label>Intr %</label>
      <input type="text" class="form-control" name="inter" 
             value="<?php echo isset($row['inter']) ? $row['inter'] : '15'; ?>" placeholder="2">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Loan Amount</label>
      <input type="text" class="form-control" name="totalhpamt" 
             value="<?php echo isset($row['totalhpamt']) ? $row['totalhpamt'] : ''; ?>" placeholder="Loan Amount">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Given Amount</label>
      <input type="text" class="form-control" name="hpamount" 
             value="<?php echo isset($row['hpamount']) ? $row['hpamount'] : ''; ?>" placeholder="Loan Amount">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Pre Interest</label>
      <input type="text" class="form-control" name="preinc" 
             value="<?php echo isset($row['preinc']) ? $row['preinc'] : ''; ?>" placeholder="interest">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Loan Date</label>
      <input type="date" class="form-control" name="hpdate" 
             value="<?php echo isset($row['hpdate']) ? $row['hpdate'] : ''; ?>">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Due Date</label>
      <input type="date" class="form-control" name="hpdate2" 
             value="<?php echo isset($row['hpdate2']) ? $row['hpdate2'] : ''; ?>">
    </div>
  </div>

  <div class="col-lg-4">
    <div class="form-group has-error has-feedback">
      <label>Due Month</label>
      <input type="text" class="form-control" name="duemnt" 
             value="<?php echo isset($row['duemnt']) ? $row['duemnt'] : ''; ?>" placeholder="Due Month">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Penalty/per Month</label>
      <input type="text" class="form-control" name="defamt" 
             value="<?php echo isset($row['defamt']) ? $row['defamt'] : ''; ?>">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Principle part</label>
      <input type="text" class="form-control" name="dueamt" 
             value="<?php echo isset($row['dueamt']) ? $row['dueamt'] : ''; ?>" placeholder="Due Amount">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Interest Part</label>
      <input type="text" class="form-control" name="interest" 
             value="<?php echo isset($row['interest']) ? $row['interest'] : ''; ?>" placeholder="Interest">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Total Due Amount</label>
      <input type="text" class="form-control" name="total" 
             value="<?php echo isset($row['total']) ? $row['total'] : ''; ?>" placeholder="Total Amount">
    </div>
  </div>

  <div class="col-lg-4">
    <div class="form-group has-error has-feedback">
      <label>Pay mode</label>
      <select class="form-control" name="pmode">
        <option <?php echo (isset($row['pmode']) && $row['pmode']=="Cash A/c") ? "selected" : ""; ?>>Cash A/c</option>
        <?php 
          $abank = mysqli_query($conn, "SELECT * FROM ledger WHERE under='Bank Accounts'");
          while($bbank = mysqli_fetch_array($abank)) {
            $selected = (isset($row['pmode']) && $row['pmode']==$bbank['ledger']) ? "selected" : "";
            echo "<option $selected>".$bbank['ledger']."</option>";
          }
        ?>
      </select>
    </div>

    <div class="form-group has-error has-feedback">
      <label>Net_Payable</label>
      <input type="text" class="form-control" name="netamt" 
             value="<?php echo isset($row['netamt']) ? $row['netamt'] : ''; ?>">
    </div>

    <div class="form-group has-error has-feedback">
      <label>Documentation Charge</label>
      <input type="text" class="form-control" name="document" 
             value="<?php echo isset($row['document']) ? $row['document'] : ''; ?>" placeholder="Documentation Charge">
    </div>

    <div class="form-group has-warning has-feedback">
      <label>Remarks</label>
      <textarea class="form-control" rows="3" cols="3" name="remarks"><?php echo isset($row['remarks']) ? $row['remarks'] : ''; ?></textarea>
    </div>
  </div>

  <!-- ================= GUARANTOR DETAILS ================= -->
  <div class="col-lg-12">
    <h3 style="background:#f5f5f5;padding:10px;border-radius:5px;">Guarantor Details</h3>
  </div>

  <div class="col-lg-4">
    <div class="form-group has-success has-feedback">
      <label>Guarantor Name <font color="red">*</font></label>
      <input type="text" class="form-control" name="nname" 
             value="<?php echo isset($row['nname']) ? $row['nname'] : ''; ?>" placeholder="Name">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Guarantor Mobile Number <font color="red">*</font></label>
      <input type="text" class="form-control" name="npno" 
             value="<?php echo isset($row['npno']) ? $row['npno'] : ''; ?>" placeholder="Eg: 9876543210">
    </div>
    
    <div class="form-group has-success has-feedback">
      <label>Guarantor Address</label>
      <input type="text" class="form-control" name="naddress" 
             value="<?php echo isset($row['naddress']) ? $row['naddress'] : ''; ?>" placeholder="Line 1">
      <input type="text" class="form-control" name="naddress1" 
             value="<?php echo isset($row['naddress1']) ? $row['naddress1'] : ''; ?>" placeholder="Line 2">
      <input type="text" class="form-control" name="naddress2" 
             value="<?php echo isset($row['naddress2']) ? $row['naddress2'] : ''; ?>" placeholder="Line 3 + Pincode">
    </div>
  </div>

  <div class="col-lg-4">
    <div class="form-group has-success has-feedback">
      <label>Guarantor Mobile Number 1 <font color="red">*</font></label>
      <input type="text" class="form-control" name="npno1" 
             value="<?php echo isset($row['npno1']) ? $row['npno1'] : ''; ?>" placeholder="Eg: 9876543210">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Guarantor House Own/Rent</label>
      <select class="form-control" name="nhouserent">
        <option>Select</option>
        <option <?php echo (isset($row['nhouserent']) && $row['nhouserent']=="Own House") ? "selected" : ""; ?>>Own House</option>
        <option <?php echo (isset($row['nhouserent']) && $row['nhouserent']=="Own by Family Member") ? "selected" : ""; ?>>Own by Family Member</option>
        <option <?php echo (isset($row['nhouserent']) && $row['nhouserent']=="Rent House") ? "selected" : ""; ?>>Rent House</option>
        <option <?php echo (isset($row['nhouserent']) && $row['nhouserent']=="Hostel/Mansion") ? "selected" : ""; ?>>Hostel/Mansion</option>
      </select>
    </div>
    
    <div class="form-group has-success has-feedback">
      <label>Guarantor Area <font color="red">*</font></label>
      <select class="form-control" name="narea">
        <option></option>
        <?php
          $sql11 = mysqli_query($conn, "SELECT * FROM msarea ORDER BY name ASC");
          while($row11 = mysqli_fetch_array($sql11)) {
            $selected = (isset($row['narea']) && $row['narea']==$row11['name']) ? "selected" : "";
            echo "<option $selected>".$row11['name']."</option>";
          }
        ?>
      </select>
    </div>
    
    <div class="form-group has-success has-feedback">
      <label>Guarantor Land Mark</label>
      <input type="text" class="form-control" name="nlmark" 
             value="<?php echo isset($row['nlmark']) ? $row['nlmark'] : ''; ?>">
    </div>
  </div>

  <div class="col-lg-4">
    <div class="form-group has-success has-feedback">
      <label>Guarantor Govt ID <font color="red">*</font></label>
      <input type="text" class="form-control" name="ngg1" 
             value="<?php echo isset($row['ngg1']) ? $row['ngg1'] : ''; ?>" placeholder="Govt ID No">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Attachment 1</label>
      <input type="file" class="form-control" name="nupp1">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Guarantor Govt ID (Alternate)</label>
      <input type="text" class="form-control" name="ng2" 
             value="<?php echo isset($row['ng2']) ? $row['ng2'] : ''; ?>" placeholder="Govt ID No">
    </div>

    <div class="form-group has-success has-feedback">
      <label>Attachment 2</label>
      <input type="file" class="form-control" name="nupp2">
    </div>
  </div>
  <div class="col-lg-12">
    <div class="form-group has-success has-feedback">
      <button type="submit" class="btn btn-success btn-block" name="s1">Save This</button>
    </div>
  </div>

</div>
</form>

      <div class="alert alert-success">
	 <?php
if (isset($_POST['s1'])) {
    extract($_POST);

   

    // If no new upload, keep old file name
    $upp1 = !empty($_FILES['upp1']['name']) ? $_FILES['upp1']['name'] : $row['upp1'];
    $upp2 = !empty($_FILES['upp2']['name']) ? $_FILES['upp2']['name'] : $row['upp2'];
    $nupp1 = !empty($_FILES['nupp1']['name']) ? $_FILES['nupp1']['name'] : $row['nupp1'];
    $nupp2 = !empty($_FILES['nupp2']['name']) ? $_FILES['nupp2']['name'] : $row['nupp2'];

    $update = mysqli_query($conn, "UPDATE customerdetailsw SET 
        mfin='$mfin',
        scode='$scode',
        hpl='$hpl',
        hplt='$hplt',
        name='$name',
        pno='$pno',
        fname='$fname',
        pnoresi1='$pnoresi1',
        address='$address',
        address1='$address1',
        address2='$address2',
        houserent='$houserent',
        rdate='$rdate',
        area='$area',
        gg1='$gg1',
        upp1='$upp1',
        g2='$g2',
        upp2='$upp2',
        lmark='$lmark',
        nname='$nname',
        npno='$npno',
        naddress='$naddress',
        naddress1='$naddress1',
        naddress2='$naddress2',
        npno1='$npno1',
        nhouserent='$nhouserent',
        narea='$narea',
        nlmark='$nlmark',
        ngg1='$ngg1',
        nupp1='$nupp1',
        ng2='$ng2',
        nupp2='$nupp2',
        inter='$inter',
        totalhpamt='$totalhpamt',
        hpamount='$hpamount',
        preinc='$preinc',
        hpdate='$hpdate',
        hpdate2='$hpdate2',
        duemnt='$duemnt',
        defamt='$defamt',
        dueamt='$dueamt',
        interest='$interest',
        total='$total',
        pmode='$pmode',
        netamt='$netamt',
        document='$document',
        remarks='$remarks'
        WHERE id='$idd' ");  // use your actual key column

    if ($update) {
        
        if (!empty($_FILES['upp1']['name'])) {
            move_uploaded_file($_FILES['upp1']['tmp_name'], "user/" . $upp1);
        }
        if (!empty($_FILES['upp2']['name'])) {
            move_uploaded_file($_FILES['upp2']['tmp_name'], "user/" . $upp2);
        }
        if (!empty($_FILES['nupp1']['name'])) {
            move_uploaded_file($_FILES['nupp1']['tmp_name'], "user/" . $nupp1);
        }
        if (!empty($_FILES['nupp2']['name'])) {
            move_uploaded_file($_FILES['nupp2']['tmp_name'], "user/" . $nupp2);
        }

        echo "<script>alert('Updated successfully');window.location.href='all2.php'</script>";
    } else {
        echo "Update Failed: " . mysqli_error($conn);
    }
}
?>

   </div>
</form>
    
   
</div> 
</div>
</div></div>
</div></div></div><?php include "layouts/footer2.php"; ?>
 <script src="vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->

    <!-- NProgress -->

    <script src="vendors/jQuery-Smart-Wizard/js/jquery.smartWizard.js"></script>
    <!-- Custom Theme Scripts -->
    <script src="build/js/custom.min.js"></script>
</body></html>
