Build a Simple To-Do List Application with PHP & Ajax

To-do lists are a great way to allow users to manage their daily tasks. User can add/update their do items, close the list items when completed, and also remove these permanently from a complete list
In this tutorial, we will build our own Do-list application with Ajax, PHP and MySQL.This is a very simple example, you can just copy paste and change according to your requirement.
Before started to implement the To-Do List Application with PHP, look files structure:
  • build-to-do-list-application-with-php-mysql-ajax
    • css
      • style.css
      • todo.css
    • js
      • todo.js
    • templates
      • header.php
      • footer.php
    • class
      • DBConnection.php
      • Task.php
    • index.php
    • action.php
Step 1: Create the database and Table
For this tutorial, you need a MySQL database with the following table:
Step 2: Database Connection class
Create a controller file named DBConnection.php inside “class/” folder.
Step 3: Create a class file
Create a class file named Task.php inside “class/” folder.
  • The Task class handles the task process.
  • __construct() – Loads the required class.
  • createTask() – Insert recored in database
  • updateTask() – Update record in database
  • getAllTask() – Get record from database
  • deleteTask() – Delete record from database
Step 4: Create action file named action.php
Step 5: Create HTML file named index.php
We will create HTML file with an input and submit button to add and list Do-list items with out refresh page.
Step 6: Create JavaScript file named todo.js
We will handle AJAX request
Create files named (header.php and footer.php)
This file contains the header and footer section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header and footer section.
header.php
footer.php