almystersv Posted February 19, 2008 Share Posted February 19, 2008 Hi Guys, I have this page that allocates tasks to the users of my system. Unfortunately at the moment I cannot get it to write it to the database properly. I think I need to include a loop as there can be up to 10 tasks that need allocating. At the moment all that is written to the database is one record where taskID = 0, empID = 0 and weekday = Monday and Complete = N. Where it should be writing each of the taskIDs and all the selected empIDs. TaskAdmin.php <?php session_start(); if ((isset($_SESSION['username']) == false) || (($_SESSION['type']) == 'user')){ header("Location: login.php"); exit(); } require "connect.php"; $query = "select * from task where weekday = 'Monday' OR weekday = 'Everyday' ORDER BY taskID"; $result = mysql_query($query, $connection) or die ("Unable to perform query $query"); $query2 = "select * from employee where active = 'y'"; $result2 = mysql_query($query2, $connection) or die ("Unable to perform query $query2"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Task Allocation</title> <link rel="stylesheet" type="text/css" href="mystylelogin.css" /> </head> <body> <?php include ("headerAdmin.php"); include ("TasksHeaderAdmin.php"); ?> <div id="Adminheader">Monday Task Allocation</div> <div id="AdminMainTable"> <table width="860" > <hr /> <tr> <th width="142"><div align="left" class="style2">Task Name</div></th> <th width="262"><div align="left" class="style2">Description</div></th> <th width="140"><div align="left" class="style2">Weekday</div></th> <th width="140"><div align="left" class="style2">Assign</div></th> </tr> <?php //Build Select Menu $employee_list = '<select name="empName"><option>Select an Employee</option>'; while ($row2 = mysql_fetch_array($result2)) $employee_list .= '<option>'.$row2['fName'].' '.$row2['sName'].'</option>'; $employee_list .= '</select>'; while($row = mysql_fetch_array($result)) { ?> <tr> <td height="27"><?php echo $row['taskName']; ?></td> <td><?php echo $row['taskDescription']; ?></td> <td><?php echo $row['weekday']; ?></td> <td> <form><?php echo $employee_list; ?></form></td> </tr> <?php } ?></td> </tr> </table> <form action="taskAdminQuery.php"> <input name="Save" type="submit" value="Allocate Tasks" /> </form> </div> </body> </html> taskAdminQuery.php <?php require "connect.php"; //$empName = $_GET['empName']; $empID = $_GET['empName']; $taskID = $_GET['taskID']; $query = "insert into emptask (taskID, empID, emptaskweekDay, complete) values ('".$taskID."','".$empID."','Monday','N')"; $result = @mysql_query($query, $connection) or die ("Error:".mysql_error()); $message1 = "Tasks Allocated Successfully."; header("Location: TaskAdmin.php?message1=$message1"); exit(); //} ?> Any help would be brilliant. Thanks Quote Link to comment Share on other sites More sharing options...
almystersv Posted February 27, 2008 Author Share Posted February 27, 2008 any help anyone please? Quote Link to comment Share on other sites More sharing options...
poirot Posted February 27, 2008 Share Posted February 27, 2008 Your HTML is wrong; the empName stuff is out of the form that is being sent. Plus, there are only 2 variables being sent to taskAdminQuery.php; which are $_GET['empName'] and $_GET['taskID']. You need to use arrays in the forms (that's HTML) to send more than 1 taskID and empName. If I can recall, something like this: <select name="empID[]"> should work. Then use a loop (like foreach) in PHP to work with the submitted array. By the way, use POST instead of GET. Quote Link to comment Share on other sites More sharing options...
almystersv Posted February 27, 2008 Author Share Posted February 27, 2008 hi, thanks for taking a look. Im not quite sure how to implement that but wil try and look into it. Any further help and guidance would be brilliant Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.