Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP CRUD Operations with PHP Creating Records Adding Tasks

Parse error: syntax error, unexpected ';' in /home/treehouse/workspace/task.php on line 14

I have the following parse error displaying while trying to work through the tasks in this lesson:

Parse error: syntax error, unexpected ';' in /home/treehouse/workspace/task.php on line 14

My POST code in task.php is:

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
     $project_id = trim(filter_input(INPUT_POST, 'project_id', FILTER_SANITIZE_NUMBER_INT));
     $title = trim(filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING));
     $date = trim(filter_input(INPUT_POST, 'date', FILTER_SANITIZE_STRING));
     $time = trim(filter_input(INPUT_POST, 'time', FILTER_SANITIZE_NUMBER_INT));

     if (empty($project_id) || (empty($title) || (empty($date) || empty($time)) {
         $error_message = 'Please fill in the required fields: Project, Title, Date, Time';
     } else {
         if (add_task($project_id, $title, $date, $time)) {
             header('Location: task_list.php');
             exit;
         } else {
             $error_message = 'Could not add task.';
         }
     }
}

I can't see an unexpected semicolon in my code above. Can anyone else point me in the right direction of what is going wrong with my code?

2 Answers

I have not gotten this far in PHP yet, so my insight may be suspect, but I noticed that you have opening parens which are not closed around (empty($title) and (empty($date). Perhaps that could be part of the issue?

That's right! I didn't even notice that! Awesome :)

Edward Del Monico
PLUS
Edward Del Monico
Courses Plus Student 8,777 Points

For future reference, a good editor can go a long way in helping sort out missing brackets, parens, curly braces, etc. A quick tip when starting out is to always write parens, brackets and curly braces in pairs and then back space into them so you do not forget them when writing long functions or statements. It will definitely save you some wasted time if you develop this habit.