我有两张桌子。员工(Employee_ID,First_name,Last_name,Address等)和培训(Training_ID,Employee_ID,First_name,Last_name,Training_type)。
对于培训表,我有一个表格,填写表格,为员工分配培训类型。
目前正常,员工ID的下拉框中包含员工表中员工ID的值。
当我从下拉框中选择一个值时,我希望更新表单(firstname和ampname)中的文本字段,显示该employee_id的名称。我在网上搜索但不知道如何做到这一点。
下面显示我的表单(PHP)
<html>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hrmwaitrose", $con);
?>
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<title>Training</title>
</head>
<body>
<div id="content">
<h1 align="center">Add Training</h1>
<form action="inserttraining.php" method="post">
<div>
<p>Training ID: <input type="text" name="Training_ID"></p>
<p>Employee ID:<select id="Employee_ID">
<?php
$result = mysql_query("SELECT Employee_ID FROM Employee");
while ($row = mysql_fetch_row($result)) {
echo "<option value=$row[0]>$row[0]</option>";
}
?>
</select>
<p>First name: <input type="text" name="First_name"></p>
<p>Last name: <input type="text" name="Last_name"></p>
<p>
Training required?
<select name="Training">
<option value="">Select...</option>
<option value="Customer Service">Customer Service</option>
<option value="Bailer">Bailer</option>
<option value="Reception">Reception</option>
<option value="Fish & meat counters">Fish & meat counters</option>
<option value="Cheese counters">Cheese counters</option>
</select>
</p>
<input type="submit">
</form>
</div>
</body>
</html>
这是我按下提交按钮时的PHP代码。
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hrmwaitrose", $con);
$sql="INSERT INTO training (Training_ID, Employee_ID, First_name, Last_name, Training)
VALUES
('$_POST[Training_ID]','$_POST[Employee_ID]','$_POST[First_name]','$_POST[Last_name]','$_POST[Training]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>