almystersv Posted February 11, 2008 Share Posted February 11, 2008 Hi Guys, I am gettins stuck on this section of my website. Its function is to alocate users specific tasks. At the moment though, the code does not seem to carry across the variables 'taskID', 'empID', emptaskweekDay'. As i am getting the error message "Unable to perform query insert into emptask values ('','','','N')" It is probably something very simple but I have tried a number of things and cannot get it to work. Here is my taskadmin page code <?php session_start(); if (isset($_SESSION['username']) == false && ($_SESSION['type']) == 'user' && ($_SESSION['type']) == 'manager'){ 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> Here is my taskAdminQuery code <?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"); $message1 = "Tasks Allocated Successfully."; header("Location: TaskAdmin.php?message1=$message1"); exit(); //} ?> Any help will be greatly appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 Your Problem is HERE <?php $query = "insert into emptask values ('".$taskID."','".$empID."','".$emptaskweekDay."','N')"; ?> Should be <?php $query = "INSERT INTO `emptask` (`field1`,`field2`,`field3`,`field4`) VALUES ('$taskID','$empID','$emptaskweekDay','N')"; ?> Replace Field1, Field2,Field3,Field4 with your mysql fields, each value asigned to the field in the order given for both sides. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 11, 2008 Share Posted February 11, 2008 this just made me laugh <?php $query = "insert into emptask values ('".$taskID."','".$empID."','".$emptaskweekDay."','N')"; $result = @mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); ?> @ to suppress it but then an or die to push the error ? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 And Some Good Resources Next Time: http://www.google.ca/search?hl=en&q=PHP+mysql+INSERT&btnG=Google+Search&meta= http://www.w3schools.com/php/php_mysql_insert.asp http://www.php-mysql-tutorial.com/mysql-insert-php.php http://www.tizag.com/mysqlTutorial/mysqlinsert.php Note: As Cooldude(still laughing) said, you should add a or die(mysql_error()); to "push" the error right out of the query, and into the browser. Quote Link to comment Share on other sites More sharing options...
almystersv Posted February 11, 2008 Author Share Posted February 11, 2008 this is the error that is gettin spat back Error:Cannot add or update a child row: a foreign key constraint fails (`bisportal/emptask`, CONSTRAINT `emptask_ibfk_3` FOREIGN KEY (`taskID`) REFERENCES `task` (`taskID`)) Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 InnoDB also supports foreign key constraints. The syntax for a foreign key constraint definition in InnoDB looks like this: InnoDB rejects any INSERT or UPDATE operation that attempts to create a foreign key value in a child table if there is no a matching candidate key value in the parent table. Quote Link to comment Share on other sites More sharing options...
almystersv Posted February 11, 2008 Author Share Posted February 11, 2008 hi I have removed the primary key and foreign key constraints in my database and now it is working! Thanks Quote Link to comment Share on other sites More sharing options...
almystersv Posted February 11, 2008 Author Share Posted February 11, 2008 I cannot seem to find a "topic solved" button anywhere!? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 I cannot seem to find a "topic solved" button anywhere!? lol, don't worry man, there was a forum update 2 days ago I think, so that button is not functional for the moment. Just Modify your post if possible, and put a giant TOPIC SOLVED text. Quote Link to comment Share on other sites More sharing options...
almystersv Posted February 11, 2008 Author Share Posted February 11, 2008 Topic Solved 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.