Hi! Could we please enable some services and cookies to improve your experience and our website?
No, thanks.
Okay!
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
CREATE DATABASE todo_list;
USE todo_list;
CREATE TABLE tasks (
id INT AUTO_INCREMENT PRIMARY KEY,
task VARCHAR(255) NOT NULL,
status TINYINT(1) DEFAULT 0
);
SQL Server:
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
MySQL 9.3.0
MariaDB 11.4
MariaDB 11.8
MariaDB 10
MariaDB 10 Sakila (ReadOnly)
SQLite 3
SQLite 3 Preloaded
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
PostgreSQL 16
PostgreSQL 17 + PostGIS
PostgreSQL 17 + PostGIS WorkShop (ReadOnly)
MS SQL Server 2017
MS SQL Server 2019
MS SQL Server 2022
MS SQL Server 2022 AdventureWorks (ReadOnly)
Firebird 4.0
Firebird 4.0 (Employee)
RedDatabase 5.0
Oracle Database 19c (HR)
Oracle Database 21c
Oracle Database 23c Free
SOQOL
ClickHouse
Run SQL code
Save snippet
ER Diagram
<?php
include 'db.php';
// Add Task
if (isset($_POST['add'])) {
$task = $_POST['task'];
$sql = "INSERT INTO tasks (task) VALUES ('$task')";
$conn->query($sql);
}
// Mark as Completed
if (isset($_GET['complete'])) {
$id = $_GET['complete'];
$conn->query("UPDATE tasks SET status=1 WHERE id=$id");
}
// Delete Task
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$conn->query("DELETE FROM tasks WHERE id=$id");
}
// Fetch Tasks
$result = $conn->query("SELECT * FROM tasks ORDER BY id DESC");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To-Do List</title>
<style>
body { font-family: Arial, sans-serif; margin: 50px; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { border: 1px solid #ddd; padding: 10px; text-align: left; }
th { background-color: #f4f4f4; }
.completed { text-decoration: line-through; color: green; }
</style>
</head>
<body>
<h2>To-Do List</h2>
<form method="POST">
<input type="text" name="task" required>
<button type="submit" name="add">Add Task</button>
</form>
<table>
<tr>
<th>Task</th>
<th>Actions</th>
</tr>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td class="<?= $row['status'] ? 'completed' : '' ?>">
<?= $row['task'] ?>
</td>
<td>
<?php if (!$row['status']): ?>
<a href="?complete=<?= $row['id'] ?>">✔ Complete</a>
<?php endif; ?>
<a href="?delete=<?= $row['id'] ?>" onclick="return confirm('Delete this task?')">🗑 Delete</a>
</td>
</tr>
<?php endwhile; ?>
</table>
</body>
</html>
PHP version :
PHP 7.4
PHP 8.0
PHP 8.1
PHP 8.2
PHP 8.3
PHP 8.4
Run PHP Code
Save snippet