To-do list using PHP and MySQLi
<?php
// Fill in your database hostname, username, password and database name below
$mysqli = new mysqli("localhost", "root", "", "to_do_list");
if(!$mysqli)
{
die("Error: Cannot connect to the database");
}
?>
ADD TASK SCRIPT
<?php
// Check to be sure that the only request we can process is POST REQUEST
if(isset($_SERVER["REQUEST_METHOD"]) && strip_tags($_SERVER["REQUEST_METHOD"]) == strip_tags("POST"))
{
if(isset($_POST['add']))
{
if( isset($_POST['task']) && !empty($_POST['task']) ) // Be sure the task brought here is not an empty field
{
// Variable declaration
$task = trim(strip_tags(htmlspecialchars($_POST['task'])));
// Save the task into the database
mysqli_query($mysqli, "insert into `task` values(0, '".mysqli_real_escape_string($mysqli, $task)."', '".mysqli_real_escape_string($mysqli, 'Pending')."')") or die(mysqli_errno());
mysqli_query($mysqli, "delete from `task` order by `task_id` asc limit 1");
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
}
else
{
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
}
}
else
{
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
//die('Sorry, no proper data was passed');
}
}
else
{
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
// Deny access if the request brought to this page is not a POST REQUEST
//die('Access Denied');
}
?>
UPDATE TASK SCRIPT
<?php
// Check to be sure that the only request we can process is POST REQUEST
if(isset($_SERVER["REQUEST_METHOD"]) && strip_tags($_SERVER["REQUEST_METHOD"]) == strip_tags("GET"))
{
if(isset($_GET['task_id']) && !empty($_GET['task_id'])) // Be sure the task ID brought here is not an empty field
{
// Variable declaration
$task_id = trim(strip_tags($_GET['task_id']));
// Update the database to set the task to Completed
mysqli_query($mysqli, "update `task` set `status` = '".mysqli_real_escape_string($mysqli, 'Completed')."' where `task_id` = '".mysqli_real_escape_string($mysqli, $task_id)."' limit 1") or die(mysqli_errno());
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
}
else
{
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
//die('Sorry, no proper data was passed');
}
}
else
{
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
// Deny access if the request brought to this page is not a GET REQUEST
//die('Access Denied');
}
?>
DELETE TASK SCRIPT
<?php
// Check to be sure that the only request we can process is POST REQUEST
if(isset($_SERVER["REQUEST_METHOD"]) && strip_tags($_SERVER["REQUEST_METHOD"]) == strip_tags("GET"))
{
if(isset($_GET['task_id']) && !empty($_GET['task_id'])) // Be sure the task ID brought here is not an empty field
{
// Variable declaration
$task_id = trim(strip_tags($_GET['task_id']));
// Delete the task from the database
mysqli_query($mysqli, "delete from `task` where `task_id` = '".mysqli_real_escape_string($mysqli, $task_id)."' limit 1") or die(mysqli_errno());
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
}
else
{
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
//die('Sorry, no proper data was passed');
}
}
else
{
echo "<script>window.location='index.php'</script>"; // Redirect back to index.php page
// Deny access if the request brought to this page is not a GET REQUEST
//die('Access Denied');
}
?>
The script is very easy to understand and customize with programming code comments to ease usability.
Screen Shots
Click on a photo below to scroll through the screen shots of the application!
Submit your Job or Project Today!
We can help you turn your idea into reality, take over your existing project, or extend your current development team.
Submit your idea job or project below and we will follow up with you shortly.
OUR OBJECTIVE
Our objective is to reach a place where our services will be highly regarded by businesses from various industrial domains for building their innovative busines solutions with our cutting-edge technological expertise, interactive designs and uncompromised quality.
OUR MISSION
We aspire to help businesses ranging from startups to enterprises, who reach out to us with their requirements, in achieving great lengths, expanding their reach, upscaling their products, and generate a large user-base with our outstanding and cost-effective services.