如何从数据库中获取数据并使用php中的下拉列表将其显示到标签?

I would like to display the retrieve data from the database into my input area using a dropdown list also generated from the database. The problem is when a run my code the customername input area is disappearing. Can you help me with these?

Dropdown Note: My Dropdown is working I just included it.

<?php
           $connect = mysqli_connect("localhost", "root", "", "xls_db");  
         ?>
             <select name="customercode" id="customercode" class="form-control"> 
             <option value="" > -----------Customer Code----------- </option> 
         <?php
            $dd_res=mysql_query("Select DISTINCT customercode from cr18_cust_listing WHERE Status = 'Active' ");
            while($r=mysql_fetch_row($dd_res))
            { 
               echo "<option value='$r[0]'> $r[0] </option>";
            }
         ?>
            </select>

PHP to display text

<?php
        $connect = mysqli_connect("localhost", "root", "", "xls_db");  
         if(isset($_POST["customercode"]))  
        {  
      if($_POST["customercode"] != '')  
      {  
           $sql = "SELECT * FROM cr18_cust_listing WHERE customercode = '".$_POST["customercode"]."'";  
      }  
      $result = mysqli_query($connect, $sql);  

     while($r = mysqli_fetch_array($result))  
      {  


      ?>
        <div class="form group has-feedback">
            <input class="form-control" type="text" name="accntname" required="required" placeholder="Customer Name" value="<?php echo $r['customername'] ?>"><span class="glyphicon glyphicon-user form-control-feedback"></span><br />
            </div>
<?php }
       }    ?>

Missing Customer Name input Area

Screenshot

try below code You have closed textarea without open it.

<input class="form-control" name="accntname" required="required" placeholder="Customer Name" value="<?php echo $r['customername'] ?>"><span class="glyphicon glyphicon-user form-control-feedback"></span><br />

For Dropdown

<?php
$conn=new mysqli("localhost","root","","xls_db");
if($conn->connect_error)
{
     echo $conn->connect_error;
     die("sorry database connection failed");
}
         ?>
                <select name="customercode" id="customercode" class="form-control" required>
                <option value="" > -----------Customer Code----------- </option>
    <?php

$sql = "Select DISTINCT customercode from cr18_cust_listing WHERE Status = 'Active'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "<option value='";
        echo $row['customercode'];
        echo "'>";
        echo $row['customercode'];
        echo "</option>";
    }
}
    ?>

    </select>

thats it , this will work for sure