Now that we can see the list of all the tasks that we have inserted into our database, we will need to work on a single task page.
This page will work in a way that the ID of the task is defined in the URL.
So the URL will always look like /?p=view-tasks&id=2
What we need to do here, is grab the ID number from the URL with GET request, and then run an SQL query, selecting only these tasks, which have this ID in the database table.

Change the index.php file
In the code, where you are checking, if p==”view-task”, add the id variable as well.
Add the line before include command:
if(isset($_GET['id'])) {
$id = $_GET['id'];
}
Edit the view-task.php file
- Open the file
- Debug it – test, if the variable id is gotten from the URL.
- Just write an echo command somewhere in that file, which would print the $id.).
- Visit yoursite.com/?p=view-task&id=10
- Does your page echo “10” ?
- Debug your code until it works.
- Write an SQL query (mysqli_query), which would select all from todo table where id is equal to your page id.
- Write a while-loop, similar to the one as in your previous exercise.
- Inside the loop, write the HTML part of your single task file.

Marking the task as done
Now that we can successfully show any task on the single task view page, we also want to be able to mark this task as Done.
For that, we have written a form there with a submit functionality.
To the very beginning of the file, write the POST method logic with PHP.
Test the example code below.
if(isset($_POST['submit'])) {
echo "Submitted";
}
# If you click the submit button, will the word be echoed?
If this worked, continue with writing the SQL statement inside this submission check script.
First, let’s think, what the algorithm should do?
On the main page, we show the done tasks in the list, where the title is “Done tasks”. We can currently differentiate, whether the task is done or not, by the “status” value in our database.
That means, when we click this submit button here, we should change the status of this task to “1”.
So if we submit the button, we will have to update the SQL record.
Syntax for updating the SQL:
“UPDATE table SET first_name = ‘Mart’ WHERE id = 3”
So we need to run this command in the if-statement, but modify it in a way that it would work with your code.
mysqli_query($con, "SQL statement");
If you now click the button, the task should be updated, and on the main page of your site, you should see this task listed in the “Done tasks” section.