mysql - Dynamically alter drop down by the results of selecting another dynamic drop down php -
i trying populate second drop down results of first drop down box. want them dynamic mysql tables. have far, second drop down wont populate. based on results of selecting project_id
, want see tasks under selected project. appreciated!!!! yes aware of mysql_query
, vulnerabilities. intend on going after works correctly , fixing security issues.
there 3 tables involved projects
, employee
, , tasks
.
projects: project_id, project_name tasks: task_id, project_id employee: staff_id, lname, fname
code follows:
<?php require_once('mainheader.php'); require_once('db_credentials.php'); ?> <!-- latest compiled , 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 , minified javascript --> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> <div class="container"> <h2>please fill out fields 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 * projects 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 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 * tasks 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 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 * 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 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'); ?>
Comments
Post a Comment