I have write this simple coding to fetch customer name and address based on the mobile number (user provided mobile number). I have done this succesfully with **Fetch button**. But I need to do **without a button** option.

When user entered mobile number in textfield then they will go to the next field (name). If mobile number already exists in database customer name and address should fetch from database. If mobile number not exists they will enter remaining two fields. Any help?

```
require('config.php');
if(isset($_POST['submit']))
{
    $cmobile = $_POST['mobile'];
    $cname = $_POST['name'];
    $caddress = $_POST['address'];

    try
    {
        $stmt = $conn->prepare("INSERT INTO autocomplete ( mobile, name, address ) VALUES ( :cmobile, :cname, :caddress )");
        $conn->errorInfo();
        $stmt->bindParam(':cmobile', $cmobile, PDO::PARAM_STR);
        $stmt->bindParam(':cname', $cname, PDO::PARAM_STR);
        $stmt->bindParam(':caddress', $caddress, PDO::PARAM_STR);
        $stmt->execute();
    }
    catch(PDOException $e)
    {
        $e->getMessage();
    }
    if($stmt)
    {
        echo "success";
    }
    else
    {
        echo "error";
    }
}
if(isset($_POST['fetch']))
{
    $cmobile = $_POST['mobile'];

    try
    {
        $stmt = $conn->prepare("SELECT * FROM autocomplete WHERE mobile = :cmobile");
        $conn->errorInfo();
        $stmt->bindParam(':cmobile', $cmobile, PDO::PARAM_STR);
        $stmt->execute();
        while($row = $stmt->fetch(PDO::FETCH_ASSOC))
        {
            $aname = $row['name'];
            $aaddress = $row['address'];
        }
    }
    catch(PDOException $e)
    {
        $e->getMessage();
    }
    if($stmt)
    {
        echo "fetch success";
    }
    else
    {
        echo "fetch error";
    }
}

```

and

```
<form method="post" name="form" action="">
    mobile number : <input type="text" name="mobile" /><br />
    name : <input type="text" name="name" value="<?= $aname ?>" /><br />
    address : <input type="text" name="address" value="<?= $aaddress ?>" />
    <br />
    <input type="submit" name="submit" value="Submit" />
    <button name="fetch">Fetch</button>
</form>

```