In Codeville, the Grand Council of Developers often found themselves juggling numerous tasks for their Innovators’ Summit. To streamline this process, they decided to create an automated task submission form that would allow team members to submit and track their tasks efficiently. Join us as we explore how they built this system, incorporating form submissions, data validation, and task tracking.
Mayor Binary gathered the council and outlined the requirements for the task submission system:
The council started by designing an HTML form to collect task details:
html
Copy code
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Task Submission Form</title>
</head>
<body>
<h1>Submit a New Task</h1>
<form action=”submit_task.php” method=”post”>
<label for=”title”>Task Title:</label>
<input type=”text” id=”title” name=”title” required>
<br>
<label for=”description”>Description:</label>
<textarea id=”description” name=”description” required></textarea>
<br>
<label for=”assigned_to”>Assigned To:</label>
<input type=”text” id=”assigned_to” name=”assigned_to” required>
<br>
<label for=”priority”>Priority:</label>
<select id=”priority” name=”priority” required>
<option value=”low”>Low</option>
<option value=”medium”>Medium</option>
<option value=”high”>High</option>
</select>
<br>
<label for=”due_date”>Due Date:</label>
<input type=”date” id=”due_date” name=”due_date” required>
<br>
<button type=”submit”>Submit Task</button>
</form>
</body>
</html>
Next, they created a PHP script (submit_task.php) to handle the form submission and store the data in a MySQL database.
First, they created a Tasks table in their database:
SQL
Copy code
CREATE DATABASE TaskManagement;
USE TaskManagement;
CREATE TABLE Tasks (
TaskID INT AUTO_INCREMENT PRIMARY KEY,
Title VARCHAR(255) NOT NULL,
Description TEXT NOT NULL,
AssignedTo VARCHAR(100) NOT NULL,
Priority VARCHAR(50) NOT NULL,
DueDate DATE NOT NULL,
SubmissionDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
PHP Script for Form Submission
Here’s the submit_task.php script:
php
Copy code
<?php
// Database configuration
$servername = “localhost”;
$username = “root”;
$password = “”;
$dbname = “TaskManagement”;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
// Get form data
$title = $_POST[‘title’];
$description = $_POST[‘description’];
$assigned_to = $_POST[‘assigned_to’];
$priority = $_POST[‘priority’];
$due_date = $_POST[‘due_date’];
// Prepare and bind
$stmt = $conn->prepare(“INSERT INTO Tasks (Title, Description, AssignedTo, Priority, DueDate) VALUES (?, ?, ?, ?, ?)”);
$stmt->bind_param(“sssss”, $title, $description, $assigned_to, $priority, $due_date);
// Execute the statement
if ($stmt->execute()) {
echo “Task submitted successfully!”;
} else {
echo “Error: ” . $stmt->error;
}
// Close connection
$stmt->close();
$conn->close();
?>
To display the list of tasks, the council created another PHP script (view_tasks.php) that fetches tasks from the database and prints them in a table.
PHP Script for Displaying Tasks
Here’s the view_tasks.php script:
php
Copy code
<?php
// Database configuration
$servername = “localhost”;
$username = “root”;
$password = “”;
$dbname = “TaskManagement”;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
// Fetch tasks
$tasksQuery = “SELECT * FROM Tasks”;
$tasksResult = $conn->query($tasksQuery);
?>
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Task List</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 12px;
border: 1px solid #ddd;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>Task List</h1>
<table>
<thead>
<tr>
<th>Task ID</th>
<th>Title</th>
<th>Description</th>
<th>Assigned To</th>
<th>Priority</th>
<th>Due Date</th>
<th>Submission Date</th>
</tr>
</thead>
<tbody>
<?php
if ($tasksResult->num_rows > 0) {
while($row = $tasksResult->fetch_assoc()) {
echo “<tr>
<td>” . $row[‘TaskID’] . “</td>
<td>” . $row[‘Title’] . “</td>
<td>” . $row[‘Description’] . “</td>
<td>” . $row[‘AssignedTo’] . “</td>
<td>” . $row[‘Priority’] . “</td>
<td>” . $row[‘DueDate’] . “</td>
<td>” . $row[‘SubmissionDate’] . “</td>
</tr>”;
}
} else {
echo “<tr><td colspan=’7′>No tasks found</td></tr>”;
}
?>
</tbody>
</table>
</body>
</html>
<?php
$conn->close();
?>
By creating a task submission form, processing the form data, and displaying the tasks in a table, the Grand Council of Developers in Codeville successfully streamlined their task management process. These techniques are essential for building efficient data management systems and can be applied to various scenarios. Feel free to try this yourself and expand upon the basic implementation provided. If you have any questions or need further assistance, I’m here to help. Happy coding!