Todo List In HTML And PHP - letsbug

     In article we are implementing todo list project in HTML but this time we are taking it one step forward. In this project we are using PHP as our backed server. 

    This is going to be just like the previous one but here with php we will not save the todos to the database. In a todos.txt file. So if user adds some todos it will be saved in the file and even if he closes the site. Whenever he will revisit he will be able to see those todos.

Prerequisite: 
  1. Basic
    1. HTML
    2. CSS
    3. JAVASCRIPT
  2. PHP CONCEPTS 
    1. Requests - POST
    2. Writing to files
    3. Reading the files
    So without wasting our time let's just start. But before that let's see our project folder structure.

    - TODOLIST 
        - index.php
        - todos.txt

Todo List In HTML And PHP

    Before jumping in this project you should first visit the last project that we did by clicking over here.

code: index.php

<!-- todo list in php -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TODO List In PHP </title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body{
            background: #f2f2f2;
            width: 100%;
            height: 100vh;
            display:grid;
            place-items:center;
        }
        .container{
            background: #fff;
            padding: 2em;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.5);
            border: 1px solid #ccc;
        }
        .container h1{
            text-align: center;
            margin-bottom: 30px;
            font-weight: ligher;
        }
        .container form {
            display:flex;
            flex-direction: row;
            justify-content:space-between;
            align-items: center;
            margin-bottom: 10px;
        }
        .container form input{
            width: 75%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .container form button{
            width:20%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background: #ccc;
            color: #fff;
            cursor: pointer;
        }

        .todo-list{
            border: 1px solid #ccc;
            padding: 10px;
        }
        .todo-list ul{
            list-style: none;
        }
        .todo-list ul li{
            border-bottom: 1px solid #ccc;
            padding: .5em;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .todo-list ul li:last-child{
            border-bottom: none;
        }
        .todo-list ul li button:hover{
            cursor: pointer;
        }
    </style>
</head>
<body>
        <div class="container">
            <h1>TODO List In PHP </h1>
            <form action="index.php" method="post">
                <input type="text" name="todo" placeholder="Add todo..." require>
                <button type="submit" name="submit">Add</button>
            </form>
    <?php
        if(isset($_POST['submit'])){
            if(!empty($_POST['todo'])){
                $todo = $_POST['todo'];
                $todos = file_get_contents('todos.txt');
                $todos .= $todo . "\n";
                file_put_contents('todos.txt', $todos);
            }else{
                echo '<p style="color:red;">Please enter a todo</p>';
            }
        }
        $todos = file('todos.txt');
        // show todo in a table
        echo '<div class="todo-list">
                    <ul>';
        if(count($todos) < 1){
            echo '<li>No todos</li>';
        }else{
            foreach($todos as $todo){
                echo '<li>
                <span>'.$todo.'</span>
                </li>';
            }
        }
        echo            '</ul>
                    </div>
                </div>';
    ?>

</body>
</html>

output: 

todo list in html php - letsbug
Before adding any todos

todo list in html php - letsbug
After adding todos


You can following on github my github username is Aniket-git-hub

Comments

Categories

Big Data Analytics Binary Search Binary Search Tree Binary To Decimal binary tree Breadth First Search Bubble sort C Programming c++ Chemical Reaction and equation class 10 class 10th Class 9 Climate Complex Numbers computer network counting sort CSS Cyber Offenses Cyber Security Cyberstalking Data Science Data Structures Decimal To Binary Development diamond pattern Digital Marketing dust of snow Economics Economics Lesson 4 Email Validation English fire and ice Food Security in India Footprints Without feet Forest And Wildlife Resources game Geography Geography lesson 6 glassmorphism Glossary Graph HackerRank Solution hindi HTML image previewer India-Size And Location Insertion Sort Internet Network Status Interview Questions Introduction to cyber crime and cyber security IT javascript tricks json to CSV converter lesson 2 lesson 1 lesson 2 Lesson 3 Lesson 6 lesson 7 Life lines of National Economy life processes Linear Search Linked List lowest common ancestor Machine Learning MCQs median in array Merge sort min and max of two numbers Moment Money and Credit My Childhood Natural Vegetation and Wildlife NCERT Network connectivity devices Network Models Network Security No Men Are foreign Node.js operator overloading P5.js PHP Physical features of India Population Prime Numbers python Quick sort R language Rain on the roof Regular Expression Resources and development reversing array saakhi science Searching Algorithm Selection sort Social Media Marketing social science Software Engineering Software Testing Sorting Algorithm Stacks staircase pattern System Concepts Text Recognition The last Leaf time converter Time Passed From A Date Todo List App Tree Trending Technologies Understanding Economic Development username and password video player Visualization water resources Wired And Wireless LAN साखी
Show more

Popular Posts

Big Data MCQs(multiple choice questions) with answers - letsbug

Digital Marketing MCQ(Multiple Choice Questions) with Answers | part 1 | letsbug

Software Engineering MCQs questions with answers - letsbug