如何从SQL表中获取与选定值关联的值

I have an MS SQL table called fundedCourses which has a number of fields, crsode, crsName, etc. I want to be able to pick a crsName and then have other input fields such as crsCode with the associated value. Neither field is a primary key.

I have tried to use the SELCT FROM WHERE function, but not really sure how to refer to crsName in the crsCode php.

<?php
//Ensures connection to database
include_once 'dbConnect.php';
?>

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
    <meta charset="utf-8">
    <title></title>

</head>

<body>

    <form name="costing">

        Course name
        <select name="Course Name" id="crsName" class="form-control">
            <option> Select </option>
            <?php
        $sql = "SELECT crsName FROM fundedCourses";
        $result = sqlsrv_query($conn,$sql) or die("Couldn't execute query");
        while ($data=sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){
            echo '<option value="'.$data['crsName'].'">';
            echo $data['crsName'];
            echo "</option>";
        }
        ?>
        </select></br></br>

        Course code
        <?php
    var $crsName = crsName;
    $sql ="SELECT crsName FROM fundedCourses WHERE crsName = $crsName"
    $result = sqlsrv_query($conn,$sql) or die("Couldn't execute query");
    while ($data=sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){
        echo '<input type="text" name="crsCode" class="form-control" id="crsCode">';
        echo $data['crsCode'];
        }
    ?>
    </form>

</body>

</html>


When I pick a crsName I want the associated crsCode to populate the input field.

When I pick a crsName I want the associated crsCode to populate the input field.