我正在尝试通过第一个下拉框的结果填充我的第二个下拉列表。我想让它们从mysql表中动态化。这是我到目前为止,第二次下降不会填充。根据选择project_id
的结果,我希望只看到所选项目下的任务。所有帮助将不胜感激!!!!是的我知道mysql_query
及其漏洞。我打算在一切正常并修复所有安全问题后返回。
涉及的表格分别为projects
,employee
和tasks
。
projects: project_id, project_name
tasks: task_id, project_id
employee: staff_id, lName, fName
代码如下:
<?php
require_once('mainheader.php');
require_once('db_credentials.php');
?>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<div class="container">
<h2>Please fill out all fields to register new Customers</h2>
<form action="task_assignment_handler.php" method="post">
<form class="form-vertical" role="form">
<?php
mysql_connect( $db_hostname, $db_username, $db_userpass ) or die(mysql_error());
mysql_select_db( $db_dbname ) or die(mysql_error());
$projsql = mysql_query("SELECT * FROM projects WHERE activeproject ='open'")
or die(mysql_error());
while($ProjectResults = mysql_fetch_array( $projsql ))
{
$proj_id = $ProjectResults['project_id'];
$proj_name = $ProjectResults['project_name'];
$project_block .= '<OPTION value="'.$proj_id.'">'.$proj_name.'</OPTION>';
}
?>
<div>
<label for="customer">Select a Project</label>
<select name="task_select"><?php echo $project_block; ?></select>
</div>
<?php
mysql_connect( $db_hostname, $db_username, $db_userpass ) or die(mysql_error());
mysql_select_db( $db_dbname ) or die(mysql_error());
$tasksql = mysql_query("SELECT * FROM tasks WHERE project_id=" .$proj_id)
or die(mysql_error());
while($TaskResults = mysql_fetch_array( $tasksql ))
{
$task_id = $TaskResults['task_id'];
$task_name = $TaskResults['taskname'];
$task_block .= '<OPTION value="'.$task_id.'">'.$task_name.'</OPTION>';
}
?>
<div>
<label for="customer">Select Task to assign</label>
<select name="task_select"><?php echo $task_block; ?></select>
</div>
<?php
mysql_connect( $db_hostname, $db_username, $db_userpass ) or die(mysql_error());
mysql_select_db( $db_dbname ) or die(mysql_error());
$empsql = mysql_query("SELECT * FROM employee")
or die(mysql_error());
while($empresults = mysql_fetch_array( $empsql ))
{
$employee_id = $empresults['staff_id'];
$employee_fname = $empresults['fName'];
$employee_lname = $empresults['lName'];
$employee_block .= '<OPTION value="'.$employee_id.'">'.$employee_fname.' '.$employee_lname.'</OPTION>';
}
?>
<div>
<label for="employee">Assign Employee to Task</label>
<select name="employee_select"><?php echo $employee_block; ?></select>
</div>
<button type="submit" class="btn btn-default">Assign Task</button>
</div>
<?php
require_once('mainfooter.php');
?>