I get value of mrno and name by get method from the landing page. Its working fine till that point. But the problem start when I tried to get Previous Amount value from the existing table of mysql database using script . Its work fine when I manually enter mrno in first field as it successfully extract Previous Amount value from database. But as per my requirement, I only have to enter advance amount field, but in that case I unable to extract previous Amount value from the database as i didnt do keyup for mrno. How can i achieve that ?? Below is my code
<?php 
include "config.php";
if (isset($_GET['id'])) {
    $user_id = $_GET['id']; 
    $sql = "SELECT * FROM mis6 WHERE `id`='$user_id'";
    $result = $link->query($sql); 
    if ($result->num_rows > 0) {        
        while ($row = $result->fetch_assoc()) {
                $mrno = $row['mrno'];
        $name1 = $row['name1'];
        ;              
        } } }
    ?>                           
                 <form>     
        <label>MR No:</label> <input type="text" name= "mrno"  id= "mrno" value="<?php echo $mrno; ?>"  onkeyup ="GetDetail(this.value)" value="">
        <label>Name:</label> <input type="text" name= "name1"  id= "name1"  value="<?php echo $name1; ?>" >
        <label>Advance Amount</label> <input type="text" name= "advamt"  id= "advamt" >
        <label>Previous Amount:</label> <input type="text" name= "padv"  id= "padv" >
        <input type="submit" name="submit" id="submit" value="Submit"  class="btn btn-success submit_btn invoice-save-btm">
<script>
        // onkeyup event will occur when the user
        // release the key and calls the function
        // assigned to this event
        function GetDetail(str) {
            if (str.length == 0) {
                document.getElementById("padv").value = "";
                
                return;
            }
            else {
                // Creates a new XMLHttpRequest object
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.onreadystatechange = function () {
                    // Defines a function to be called when
                    // the readyState property changes
                    if (this.readyState == 4 &&
                            this.status == 200) {
                        
                        // Typical action to be performed
                        // when the document is ready
                        var myObj = JSON.parse(this.responseText);
                        // Returns the response data as a
                        // string and store this array in
                        // a variable assign the value
                        // received to first name input field
                        
                        document.getElementById
                            ("padv").value = myObj[0];
                        }  };                   
                
                // xhttp.open("GET", "filename", true);
                xmlhttp.open("GET", "gfg1.php?mrno=" + str, true);
                
                // Sends the request to the server
                xmlhttp.send();
            }
        }
    </script>  </form>
// here is gfg1 file code which handle database
<?php
// Get the mrno
$mrno = $_REQUEST['mrno'];
// Database connection
$con = mysqli_connect("localhost", "thehospi_root", "u1m1a1r1", "thehospi_hmis");
if ($mrno !== "") {
    
    // Get corresponding mrno
        
    $query = mysqli_query($con, "SELECT  padv FROM mis14 WHERE mrno ='$mrno'");
    $row = mysqli_fetch_array($query);
    // Get the first name
    $ccc = $row["padv"];
    
}
// Store it in a array
$result = array("$ccc");
// Send in JSON encoded form
$myJSON = json_encode($result);
echo $myJSON;
?> 
 
    