almystersv Posted January 29, 2008 Share Posted January 29, 2008 Hi Guys, I have a page that allows the admin to allocate a number of different tasks to employees via a number of drop down menus reading from an mySQL database. I have the drop down menus functioning fine but am encountering problems when trying to get the data written into the database here is my code... <?php session_start(); if (isset($_SESSION['type']) == 'admin'){ 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"); ?> <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 value=" '.$row2['empID'].' "> '.$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 action="taskAdminQuery.php"><?php echo $employee_list; ?></td> </tr> <?php } ?> <input name="Save" type="submit" value="Allocate Tasks" /> </form> </table> <?php if(isset($_GET['message1'])) { echo $_GET['message1']; } ?> </body> </html> Here is the taskQuery page... <?php require "connect.php"; //$empName = $_GET['empName']; $empID = $_GET['empName']; $emptaskweekDay = $_GET['weekday']; $taskID = $_GET['taskID']; $query = "insert into emptask values ('".$taskID."','".$empID."','".$emptaskweekDay."', 'N')"; $result = @mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); header("Location: TaskAdmin.php"); $message1 = "Tasks Allocated Successfully."; header("Location: TaskAdmin.php?message1=$message1"); exit(); //} ?> Quote Link to comment https://forums.phpfreaks.com/topic/88355-inserting-a-number-of-records-into-a-database-with-one-button-click/ Share on other sites More sharing options...
almystersv Posted January 29, 2008 Author Share Posted January 29, 2008 I've changed the code now so that it does write the task ID, empID and weekday into the emptask table. ...But it is only writing the very last record into the database and not the ones before it. Quote Link to comment https://forums.phpfreaks.com/topic/88355-inserting-a-number-of-records-into-a-database-with-one-button-click/#findComment-452183 Share on other sites More sharing options...
almystersv Posted January 29, 2008 Author Share Posted January 29, 2008 anyone know how to get the code to write all the tasks to the database rather than just one!? Quote Link to comment https://forums.phpfreaks.com/topic/88355-inserting-a-number-of-records-into-a-database-with-one-button-click/#findComment-452312 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.