How can PHP be used to retrieve data from an MS-SQL database and display it in an existing HTML form?

To retrieve data from an MS-SQL database and display it in an existing HTML form using PHP, you can establish a connection to the database, query the database for the data you need, and then populate the form fields with the retrieved data.

<?php
// Establish a connection to the MS-SQL database
$serverName = "your_server_name";
$connectionInfo = array("Database" => "your_database_name", "UID" => "your_username", "PWD" => "your_password");
$conn = sqlsrv_connect($serverName, $connectionInfo);

// Query the database for the data
$sql = "SELECT * FROM your_table_name";
$stmt = sqlsrv_query($conn, $sql);

// Populate the form fields with the retrieved data
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
    echo '<input type="text" name="field1" value="' . $row['field1'] . '"><br>';
    echo '<input type="text" name="field2" value="' . $row['field2'] . '"><br>';
    // Add more input fields as needed
}

// Close the database connection
sqlsrv_close($conn);
?>