Task Management System

Submitted by: 
Visitors have accessed this post 3421 times.

This tutorial will is going to be on how to create a task management system in PHP... it's going to be a long one!

First you will need a host for your PHP, either a web host or localhost is fine but you will need PHP and MySQL(i) capabilities.

We are going to be storing all of the created tasks in a database named 'tasksTutorial', and in there a table named 'tasks'. Let's create these now;

Go to PHPMyAdmin and enter 'tasksTutorial' followed by pressing the 'create' button. Once it has created, click on the database and add a table, put the following information;
3 Columns:
id - INT - 5 Length - Primary Key - Auto Increment (AI/A_I).
description - VARCHAR - 255 Length.
active - BOOLEAN - 1 Length.

Now we are ready to work on the HTML Forms.

Create Task
First we want a form to add a task to populate our database. For this all we need is a description of task [You can add things such as dates, created by usernames and location etc.]...

  1. <html>
  2. <head></head>
  3. <body>
  4. <h1>Add Task:</h1>
  5. <form action='taskManagement.php' method='POST'>
  6. <table>
  7. <tbody>
  8. <tr>
  9. <td>Description of Task: </td><td><input type='text' name='desc' /></td>
  10. </tr>
  11. <tr>
  12. <td></td><td><input type='submit' value='Create Task' name='createTask' /></td>
  13. </tr>
  14. </tbody>
  15. </table>
  16. </form>
  17. </body>
  18. </html>

We have set the action to taskManagement.php as we are going to save this form page as taskManagement.php, this means we only have to create and use one page - it just makes it easier for us and the user.

Next we need the PHP;

  1. <?php
  2. $con = mysqli_connect('localhost', 'root', '', 'tasksTutorial') or die(mysql_error());
  3. if (isSet($_POST['createTask'])) {
  4. if (isSet($_POST['desc']) && $_POST['desc'] != '') {
  5. $desc = $_POST['desc'];
  6. $q = mysqli_query($con, "INSERT INTO `tasks` VALUES ('', '$desc', '1')") or die(mysql_error());
  7. if ($q) {
  8. echo 'Added task.';
  9. }else
  10. echo 'Failed to add task.';
  11. }
  12. }
  13. ?>

We first check if the submit button has been sent (if the form has been used), then we check that there is a valid description from the 'desc' field in our form. If there is a valid description we insert it to our tasks table within our database with id as nothing (due to it Auto_Incrementing through the database already), description as the form description and active as 1 (true). We finally output the end result.

Managing Tasks
So, now we can create tasks, but what about removing them? Here we go...

First we create another table to keep the data aligned;

  1. <br/>
  2. <h1>Manage Tasks:</h1>
  3. <table>
  4. <tbody>
  5. </tbody>
  6. </table>

Then, within our table/tbody, we loop through all the data we receive from a query selecting every row/entry/task from our table that is active (has the active boolean value of 1 - true)...

  1. <?php
  2. $qu = mysqli_query($con, "SELECT * FROM `tasks` WHERE `active`='1'");
  3. if (mysqli_num_rows($qu) > 0) {
  4. while ($row = mysqli_fetch_array($qu)) {
  5. echo "<tr><td>";
  6. echo $row['description'];
  7. echo "</td><td><a href='taskManagement.php?removeTask&id=".$row['id']."'>Remove Task</a></td></tr>";
  8. }
  9. }
  10. ?>

As you can probably tell, we give out the description of each found task in a column table, then a link to remove the task from the list through our "Remove Task" link text. The link on the remove text is set to a get function of "removeTask" and sends the id of the selected task along with it so we can reference it later.

Now for the actual deleting of the task;

  1. if (isSet($_GET['removeTask']) && isSet($_GET['id'])) {
  2. $id = $_GET['id'];
  3. $q = mysqli_query($con, "UPDATE `tasks` SET `active`='0' WHERE `id`='$id'");
  4. if ($q) {
  5. echo 'Task removed.';
  6. }else
  7. echo 'Failed to remove task.';
  8. }

Again, we first check whether we should actually remove anything by checking if the given information is valid, if it is we perform a simple update query on the row with the given id to change it's active value from 1 to 0 (true to false). We give out the final result through the echo statements.

Full Source:
I have not included how to edit the description of each task, try to figure that one out yourself. If you need help though, message me.

  1. <?php
  2. $con = mysqli_connect('localhost', 'root', '', 'tasksTutorial') or die(mysql_error());
  3. if (isSet($_POST['createTask'])) {
  4. if (isSet($_POST['desc']) && $_POST['desc'] != '') {
  5. $desc = $_POST['desc'];
  6. $q = mysqli_query($con, "INSERT INTO `tasks` VALUES ('', '$desc', '1')") or die(mysql_error());
  7. if ($q) {
  8. echo 'Added task.';
  9. }else
  10. echo 'Failed to add task.';
  11. }
  12. }
  13. if (isSet($_GET['removeTask']) && isSet($_GET['id'])) {
  14. $id = $_GET['id'];
  15. $q = mysqli_query($con, "UPDATE `tasks` SET `active`='0' WHERE `id`='$id'");
  16. if ($q) {
  17. echo 'Task removed.';
  18. }else
  19. echo 'Failed to remove task.';
  20. }
  21. ?>
  22. <html>
  23. <head></head>
  24. <body>
  25. <h1>Add Task:</h1>
  26. <form action='taskManagement.php' method='POST'>
  27. <table>
  28. <tbody>
  29. <tr>
  30. <td>Description of Task: </td><td><input type='text' name='desc' /></td>
  31. </tr>
  32. <tr>
  33. <td></td><td><input type='submit' value='Create Task' name='createTask' /></td>
  34. </tr>
  35. </tbody>
  36. </table>
  37. </form>
  38. <br/>
  39. <h1>Manage Tasks:</h1>
  40. <table>
  41. <tbody>
  42. <?php
  43. $qu = mysqli_query($con, "SELECT * FROM `tasks` WHERE `active`='1'");
  44. if (mysqli_num_rows($qu) > 0) {
  45. while ($row = mysqli_fetch_array($qu)) {
  46. echo "<tr><td>";
  47. echo $row['description'];
  48. echo "</td><td><a href='taskManagement.php?removeTask&id=".$row['id']."'>Remove Task</a></td></tr>";
  49. }
  50. }
  51. ?>
  52. </tbody>
  53. </table>
  54. </body>
  55. </html>


thank you for the code

i love this task

nice task ticketing system

i like these system please may you allow me to download it.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.