What are the best practices for connecting a text box in PHP with a specific database entry, such as a start address?

To connect a text box in PHP with a specific database entry, such as a start address, you need to retrieve the value from the database and populate the text box with that value. This can be done by querying the database for the specific entry and then echoing the value into the text box.

<?php
// Connect to database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

// Query database for start address
$sql = "SELECT start_address FROM your_table WHERE id = 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // Output data of each row
  while($row = $result->fetch_assoc()) {
    $start_address = $row["start_address"];
  }
} else {
  echo "0 results";
}

$conn->close();
?>

<input type="text" name="start_address" value="<?php echo $start_address; ?>">