• PHP Help PHP Coding
  • [RESOLVED] getting this error Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING i

Well other than a missing '}' for the switch() statement (could be in your code and you just didn't copy it?), I don't immediately see any parse errors... could you perhaps post your entire code as well as the exact error message?

    hi bradgrafelman this is the switch case i am attaching the jpg file along with displays the error message

    switch ($f) {
            case 'all':
                    break;
            case 'myfinished7days':
                    $where .= " AND user_tasks.user_id = $user_id";
            case 'allfinished7days':        // patch 2.12.04 tasks finished in the last 7 days
                    //$from .= ", user_tasks as ut";
                    $where .= "
                            AND t.task_project             = p.project_id
                           AND ut.task_id       = t.task_id
                            AND t.task_percent_complete    = '100'
                            AND t.task_end_date >= '" . date("Y-m-d 00:00:00", mktime(0, 0, 0, date("m"), date("d")-7, date("Y"))) . "'";
                    break;
            case 'children':
            // patch 2.13.04 2, fixed ambigious task_id
                    $where .= "\n        AND t.task_parent = $task_id AND t.task_id <> $task_id";
                    break;
            case 'myproj':
                    $where .= "\n        AND p.project_owner = $user_id";
                    break;
            case 'mycomp':
                if(!$AppUI->user_company){
                    $AppUI->user_company = 0;
                }
                    $where .= "\n        AND p.project_company = $AppUI->user_company ";
                    break;
            case 'myunfinished':
                    //$from .= ", user_tasks as ut";
                    // This filter checks all tasks that are not already in 100%
                    // and the project is not on hold nor completed
                    // patch 2.12.04 finish date required to be consider finish
                    $where .= "
                                            AND t.task_project             = projects.project_id
                                           AND ut.user_id       = $user_id
                                            AND ut.task_id       = t.task_id
                                            AND (t.task_percent_complete    < '100' OR t.task_end_date = '')
                                            AND p.projects.project_active  = '1'
                                            AND p.projects.project_status <> '4'
                                            AND p.projects.project_status <> '5'";
                    break;
            case 'allunfinished':
                    // patch 2.12.04 finish date required to be consider finish
                    // patch 2.12.04 2, also show unassigned tasks
                    $where .= "
                                            AND t.task_project             = p.project_id
                                            AND (t.task_percent_complete   < '100' OR t.task_end_date = '')
                                            AND p.projects.project_active  = '1'
                                            AND p.projects.project_status <> '4'
                                            AND p.projects.project_status <> '5'";
                    break;
            case 'unassigned':
                    //$join .= "\n LEFT JOIN user_tasks as ut2 ON t.task_id = ut2.task_id";
                    $where .= "
                                            AND ut.task_id IS NULL";
                    break;
            case 'taskcreated':
                    $where .= " AND t.task_owner = '$user_id'";
                    break;
            default:
                    $from .= ", user_tasks as ut";
                    $where .= "
            AND t.task_project = p.project_id
            AND ut.user_id = $user_id
            AND ut.task_id = t.task_id";
                    break;
    }
    

      Are you sure you're viewing the correct file as listed in the error message? The code you listed in that post contains no syntax errors (just did a "php -l" on it myself).

        hi bradgrafelman
        yes we are looking at the same file

          Only thing I can suggest is attach this "tasks.php" file to your next post (you'll probably have to rename it to a .txt extension) and let us see if it parses for us.

            hi bradgrafelman
            I am sending the url and the tasks text file along with this request please help me how to solve the above

            http://infospark.in/dp/
            username:testuser password:testuser

            goto tasks you will see the error

            please solve that error

              The error you get is "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/infospar/public_html/dp/modules/tasks/tasks.php on line 183".

              So let's look at the code near line 183:

              $where .= "
                      AND t.task_project             = p.project_id"
                     //AND ut.task_id       = t.task_id
                     " AND t.task_percent_complete    = '100'
                      AND t.task_end_date >= '" . date("Y-m-d 00:00:00", mktime(0, 0, 0, date("m"), date("d")-7, date("Y"))) . "'";

              The problem is that when commenting out some code, you turned one string literal into two, yet failed to concatenate them. You can still leave the comment in as it is a single line comment, but you should remove the closing and opening double quotes around it:

              $where .= "
                      AND t.task_project             = p.project_id
                    //AND ut.task_id       = t.task_id
                      AND t.task_percent_complete    = '100'
                      AND t.task_end_date >= '" . date("Y-m-d 00:00:00", mktime(0, 0, 0, date("m"), date("d")-7, date("Y"))) . "'";

              There is usually no need to give out usernames and passwords and access to your actual (or test) website. If you had given the full error message, I could have just used the line number to locate roughly where the error might lie.

                Also, the code you posted above is not what is in the tasks.txt file you attached, thus why I couldn't find any errors in it.

                EDIT:

                laserlight wrote:

                You can still leave the comment in as it is a single line comment

                Yes, but you must use '#' to identify comment lines in a SQL query, not '//' ! 😉

                  Yes, but you must use '#' to identify comment lines in a SQL query, not '//' !

                  Actually, I believe the SQL standard specifies --, not #, for comments, considering how it seems to be universal unlike #. Nonetheless it is a good point as I should have checked before assuming that a C++ or C99 style comment would work as in C++ or C99, especially since the string literals work differently :o

                    hi laserlight

                    when i give # symbol

                    i get following error

                    Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/infospar/public_html/dp/modules/tasks/tasks.php on line 183

                    if i remove " and // i get following error is always dotproject gives these kind of errors like that?

                    Parse error: parse error, unexpected '=' in /home/infospar/public_html/dp/modules/tasks/tasks.php on line 182

                      Bah, you're right, laserlight. Silly me, I just thought it was '#' and since it worked in MySQL, I assumed that '#' was the standard character. Guess I forgot that MySQL doesn't alwaysfollow standards when it comes to SQL syntax :p

                      EDIT: As noted, comment lines should begin with two hyphens, not a '#'.

                      If you're getting a parse error, show us what you changed your query to.

                        sigh

                        Let's keep this simple. Use:

                        $where .= "
                                AND t.task_project             = p.project_id
                                AND t.task_percent_complete    = '100'
                                AND t.task_end_date >= '" . date("Y-m-d 00:00:00", mktime(0, 0, 0, date("m"), date("d")-7, date("Y"))) . "'";

                        when i give # symbol

                        i get following error

                        Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/infospar/public_html/dp/modules/tasks/tasks.php on line 183

                        What is the exact code that you wrote?

                        if i remove " and // i get following error is always dotproject gives these kind of errors like that?

                        Parse error: parse error, unexpected '=' in /home/infospar/public_html/dp/modules/tasks/tasks.php on line 182

                        What is the exact code that you wrote?

                          hi laserlight,bradgrafelman

                          i have changed the following way please see the code it is working fine now

                          thanks

                            Write a Reply...