TO DO LIST (PHP)
INDEX.PHP
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
</div>
</nav>
<div class="col-md-3"></div>
<div class="col-md-6 well">
<h3 class="text-primary">PHP - Simple To Do List App</h3>
<hr style="border-top:1px dotted #ccc;"/>
<div class="col-md-2"></div>
<div class="col-md-8">
<center>
<form method="POST" class="form-inline" action="add_query.php">
<input type="text" class="form-control" name="task" required/>
<button class="btn btn-primary form-control" name="add">Add Task</button>
</form>
</center>
</div>
<br /><br /><br />
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Task</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
require 'conn.php';
$query = $conn->query("SELECT * FROM `task` ORDER BY `task_id` ASC");
$count = 1;
while($fetch = $query->fetch_array()){
?>
<tr>
<td><?php echo $count++?></td>
<td><?php echo $fetch['task']?></td>
<td><?php echo $fetch['status']?></td>
<td colspan="2">
<center>
<?php
if($fetch['status'] != "Done"){
echo
'<a href="update_task.php?task_id='.$fetch['task_id'].'" class="btn btn-success"><span class="glyphicon glyphicon-check"></span></a> |';
}
?>
<a href="delete_query.php?task_id=<?php echo $fetch['task_id']?>" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span></a>
</center>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</body>
</html>
CONN.PHP
<?php
$conn = new mysqli("localhost", "root", "", "db_task");
if(!$conn){
die("Error: Cannot connect to the database");
}
?>
ADD_QUERY.PHP
<?php
require_once 'conn.php';
if(ISSET($_POST['add'])){
if($_POST['task'] != ""){
$task = $_POST['task'];
$conn->query("INSERT INTO `task` VALUES('', '$task', '')");
header('location:index.php');
}
}
?>
UPDATE_TASK.PHP
<?php
require_once 'conn.php';
if($_GET['task_id'] != ""){
$task_id = $_GET['task_id'];
$conn->query("UPDATE `task` SET `status` = 'Done' WHERE `task_id` = $task_id") or die(mysqli_errno());
header('location: index.php');
}
?>
DELETE_QUERY.PHP
<?php
require_once 'conn.php';
if($_GET['task_id']){
$task_id = $_GET['task_id'];
$conn->query("DELETE FROM `task` WHERE `task_id` = $task_id") or die(mysqli_errno());
header("location: index.php");
}
?>
DATABASE
-- phpMyAdmin SQL Dump
-- version 4.7.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jun 01, 2018 at 07:22 AM
-- Server version: 10.1.24-MariaDB
-- PHP Version: 7.1.6
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `db_task`
--
-- --------------------------------------------------------
--
-- Table structure for table `task`
--
CREATE TABLE `task` (
`task_id` int(11) NOT NULL,
`task` varchar(150) NOT NULL,
`status` varchar(150) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `task`
--
INSERT INTO `task` (`task_id`, `task`, `status`) VALUES
(1, 'Check Errors', 'Done'),
(4, 'Remove Bugs', ''),
(5, 'Need Improvements', '');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `task`
--
ALTER TABLE `task`
ADD PRIMARY KEY (`task_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `task`
--
ALTER TABLE `task`
MODIFY `task_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Comments
Post a Comment