如何在PHP中的依赖下拉列表中添加值?

时间:2018-05-03 08:49:07

标签: php mysqli

我的数据库中有两列:facultydepartment。我设法将数据绑定到包含faculties的下拉列表。但对于departmentforeign key的{​​{1}},如何添加新的并在下拉菜单中显示?

基本上,我需要在第一个下拉列表中选择faculty时,第二个下拉菜单中会显示faculty departments,我可以如果我愿意,可以向选定的教师添加另一个部门。我如何实现这一目标?

faculty

1 个答案:

答案 0 :(得分:1)

请使用if condition或动态查询:

 $query = '';
    if (isset($_POST['save_department'])) {
   $query = "INSERT INTO department (name) VALUES ('" . 
   $_POST["department_name"] . "')";

    }else{
        $query = "SELECT name, faculty_id, department_ID FROM department ORDER BY name ASC";

        }

    $result = mysqli_query($con, $query);