data entry form in the MYSQL table in PHP

Question like this: What should be in the FOR Cycle, the departments are recorded in the drop-down list?

In MySQL database, there are two Prepods and CafedRS tables. The prepods table consists of two fields – Prepo and Cafedra. Cafedra also has in the CafedRS table, which is already filled. Tables are connected.

You need to create an input form to the Prepods table to PHP so that the field of the department in the table is a drop-down list and all values ​​of this field are taken from the CafedRS table (CAFEDRA field).

PHP code

<?php
if ($_POST["submit"]) {
    if (!($connection=mysql_connect ("localhost", "root", "2357610"))) die (" ");
    if (!(mysql_select_db ("imc", $connection))) die ("   ");
    $prepod=$_POST['prepod'];
    $cafedra=$_POST['cafedra'];
    if (!($cafedra=mysql_query ("SELECT cafedra from cafedrs"))) die ("");
    $count=mysql_num_fields ($cafedra);
    while ($row=mysql_fetch_array ($cafedra)) {
        for($x=0;$x<$count;$x++) {//  - }
    }
    if (($cafedra!="") or ($prepod!="")) {
        $sql=mysql_query("INSERT INTO prepods VALUES (null,'$prepod','$row[$x]',1)");
        $result=mysql_query($sql);
        echo "<script type=\"text/javascript\"> alert(\" \");</script> \n";
    } else {
        echo "<script type=\"text/javascript\"> alert(\" \");</script> \n";
    };
}
?>

Form:

<form action="pre.php" method="POST" name="form1">
    <table width="100%" align="center" valign=center>
        <tr>
            <td align=right> :</td>
            <td>
                <input type="text" name="prepod">
                <br>
            </td>
        </tr>
        <tr>
            <td align=right> :</td>
            <td>
                <select name="row"></select>
                <br>
            </td>
        </tr>
        <tr>
            <td align=right>
                <br>
                <input type="submit" name="submit" value="">
            </td>
        </tr>
    </table>
</form>

Answer 1, Authority 100%

   <form action="pre.php" method="POST" name="form1">
    <table width="100%" align="center" valign=center>
        <tr>
            <td align=right> :</td>
            <td>
                <input type="text" name="prepod">
                <br>
            </td>
        </tr>
        <tr>
            <td align=right> :</td>
            <td>
                <select name="row">
                 <?
if (!($cafedra=mysql_query ("SELECT cafedra from cafedrs"))) die ("");
    $count=mysql_num_fields ($cafedra);
    while ($row=mysql_fetch_array ($cafedra)) {
        for($x=0;$x<$count;$x++) {
         echo $row["cafedra"];
}
    }
?>
                       </select>
                <br>
            </td>
        </tr>
        <tr>
            <td align=right>
                <br>
                <input type="submit" name="submit" value="">
            </td>
        </tr>
    </table>
</form>