Vrchi.php
<?php
$query = mysql_query ("select * from vrachi") ;
$otd = array();
$row = mysql_fetch_array ($query);
$table = "<table border=0 align=center bordercolor='black' width='500'>\n";
$table .= "<tr bgcolor='gray'>
<td align=center> id </td>
<td align=center> ФИО </td>
<td align=center> Должность </td>
<td align=center> Телефон </td>
<td align=center> Кабинет </td>
<td align=center> idотдела </td>
</tr>";
while ($row = mysql_fetch_assoc($query))
{
$otd[] = $row;
$table .= "<tr>\n";
$table .= "<td bgcolor='white'>".$row['ID_VR']."</td>\n";
$table .= "<td align=center bgcolor='white'>".$row['FIO']."</td>\n";
$table .= "<td align=center bgcolor='white'>".$row['DOLGNOST']."</td>\n";
$table .= "<td align=center bgcolor='white'>".$row['TELEFON']."</td>\n";
$table .= "<td align=center bgcolor='white'>".$row['KABINET']."</td>\n";
$table .= "<td align=center bgcolor='white'>".$row['ID_OTD']."</td>\n";
$table .= "</tr>\n";
}
$table .= "</table>\n";
echo $table;
?>
vrachadd.php
<form method="post" action="insert2.php">
ФИО: <input type="text" name="FIO" />
Должность: <input type="text" name="DOLGNOST" />
телефон: <input type="text" name="TELEFON" />
кабинет: <input type="text" name="KABINET" />
idотдела: <select name="ID_OTD" />
<? foreach($otd as $o): ?>
<option value="<?=$o['ID_OTD'];?>"><?=$o['NAZVANIE'];?></option>
<? endforeach; ?>
</select>
<input type="submit" name="ok" value="Добавить" />
</form>
insert2.php
<?php
include('db.php');
$FIO = $_POST['FIO'];
$DOLGNOST = $_POST['DOLGNOST'];
$TELEFON = $_POST ['TELEFON'];
$KABINET = $_POST ['KABINET'];
$ID_OTD = $_POST ['ID_OTD'];
if (isset($_POST['ok']))
{
$query = mysql_query ("INSERT INTO vrachi (FIO,DOLGNOST,TELEFON,KABINET,ID_OTD) VALUES ('$FIO','$DOLGNOST','$TELEFON','$KABINET','$ID_OTD')") ;
echo"добавленно<a href='vrachi.php'>Обновить</a>";
}
?>