Parse error: syntax error, unexpected T_ENCAPSED_AND WHITESPACE, expecting T_STRING

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rhys
    New Member
    • Nov 2006
    • 25

    Parse error: syntax error, unexpected T_ENCAPSED_AND WHITESPACE, expecting T_STRING

    My Gurus and Angels --
    Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My shortcomings will soon become apparent.

    I am developing an estimating construction system, using PHP5 and MySQL 5.0.24a with Ubuntu. I have a main "projects" file, and 2 detail files, one for piping and one for equipment. Each of these files will have multiple entries per project, and I have further breakdowns in each, by "bid item" and "system/line." For reporting, a bid item may contain piping, or equipment, or both.

    To calculate the bid, I spin through the detail files and calculate a "subtotals" file, which is reported further down the line. I restart this subtotals file at the start of each run.

    My problems begin in piping -- equipment to come later. I need to cycle through the individual rows and crunch some numbers. If there is an existing subtotals record for the current bid item/line # combo, we will add to it. If not, we will start one -- an operation made more complicated by the return values of "select" as opposed to "insert."

    Here is a simplified version of my troubled code:

    [PHP]$presult = mysql_query("se lect * from mrb_pipe
    where pproj = '$proj'");
    while ($pipe = mysql_fetch_ass oc($presult)) {
    $tpbidit = $pipe["pbidit"];
    $tpsys = $pipe["psys"];
    $stresult = mysql_query{"se lect * from mrb_stot
    where sbidit = '$tpbidit' // select didn't like subscripted
    and ssys = '$tpsys'"); // arguments, so i made $vars
    if (mysql_num_rows ($stresult) <> 1) {
    mysql_query("in sert into mrb_stot ....) // load a new row
    or die("bummer");
    $stresult = mysql_query("se lect * from mrb_stot
    where sbidit = '$tpbidit'
    and ssys = '$tpsys'"); // load result into $stresult
    )
    $subt = mysql_fetch_ass oc($stresult);
    $mysql_free_res ult($stresult);
    getSurf(1, $pipe["psize"], $pipe["pthk"]); // function also includes
    // mysql_query
    $actstr = $pipe["pstr"]; // initialize
    $strbdsf = $actstr * $psfmlt; // $psfmlt returned by getSurf func
    $winssf = $subt["inssf"]; // will add to this work variable[/PHP]
    At this point I get a Parse error: syntax error, unexpected T_ENCAPSED
    _AND WHITESPACE, expecting T_STRING ... error, on the last line.

    I have pored over my syntax, to no avail. This line is virtually identical to the one which occurs 2 previous, and apparently works fine. I have to conclude that there is a problem with the second result set. I also had a problem using subscripted variables in math calculations, but could avert those by converting to regular $variables first.

    I have Googled many nested-query problems, but they always seem to relate to nested queries within the same select statement. Either my application is very unusual -- and I had thought it fairly simple, in need of no complex outer joins -- and/or I have some serious shortcomings in my understanding of how MySQL stores things. Most likely the latter.

    I hope I have included enough detail, that someone may grasp the essence of my issues, and suggest a better way to skin this cat!! The last time I appealed to this forum, I was embarrassed at the solution -- I should've tried that first!! I hope that is not the case this time.

    Any hints at all would be greatly appreciated! -- The Estimator's Buddy
    Last edited by mwasif; Aug 23 '07, 04:33 PM. Reason: Added code tags.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Use proper CODE tags when posting source code. Follow the POSTING GUIDELINES.

    After applying the CODE tags on your code, it clearly marked where the syntax error is.

    [PHP]$stresult = mysql_query{"se lect * from mrb_stot
    where sbidit = '$tpbidit' // select didn't like subscripted
    and ssys = '$tpsys'");[/PHP]
    Use '(' instead of '{'
    [PHP]$stresult = mysql_query("se lect * from mrb_stot
    where sbidit = '$tpbidit' and ssys = '$tpsys'");[/PHP]

    Comment

    • rhys
      New Member
      • Nov 2006
      • 25

      #3
      my bad. that was a typo only in the sample i provided, does not exist in the actual source code. I found other errors in that section, before I got the parser to make it as far as it did. But thanks for the fast response!! -- Rhys

      Comment

      • rhys
        New Member
        • Nov 2006
        • 25

        #4
        in other words, the problem still exists. And i am sorry to confuse the issue with a typo, but rest assured that is only in the example, and not my real problem. Thx!!

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Rhys.

          I'm going to go ahead and move this thread to the PHP forum, where our resident Experts will be better able to help you out.

          Changed thread title to better describe the problem.

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Is this what you have now?

            [code=php]
            $presult = mysql_query("se lect * from mrb_pipe
            where pproj = '$proj'");
            while ($pipe = mysql_fetch_ass oc($presult)) {
            $tpbidit = $pipe["pbidit"];
            $tpsys = $pipe["psys"];
            $stresult = mysql_query{"se lect * from mrb_stot
            where sbidit = '$tpbidit' // select didn't like subscripted
            and ssys = '$tpsys'"); // arguments, so i made $vars
            if (mysql_num_rows ($stresult) <> 1) {
            mysql_query("in sert into mrb_stot ....") // load a new row
            or die("bummer");
            $stresult = mysql_query("se lect * from mrb_stot
            where sbidit = '$tpbidit'
            and ssys = '$tpsys'"); // load result into $stresult
            )
            $subt = mysql_fetch_ass oc($stresult);
            $mysql_free_res ult($stresult);
            getSurf(1, $pipe["psize"], $pipe["pthk"]); // function also includes
            // mysql_query
            $actstr = $pipe["pstr"]; // initialize
            $strbdsf = $actstr * $psfmlt; // $psfmlt returned by getSurf func
            $winssf = $subt["inssf"]; // will add to this work variable
            [/code]

            And is this the line that generates the error?
            [code=php]
            $winssf = $subt["inssf"]; // will add to this work variable
            [/code]

            Comment

            • rhys
              New Member
              • Nov 2006
              • 25

              #7
              Originally posted by pbmods
              Is this what you have now?

              [code=php]
              $presult = mysql_query("se lect * from mrb_pipe
              where pproj = '$proj'");
              while ($pipe = mysql_fetch_ass oc($presult)) {
              $tpbidit = $pipe["pbidit"];
              $tpsys = $pipe["psys"];
              $stresult = mysql_query{"se lect * from mrb_stot
              where sbidit = '$tpbidit' // select didn't like subscripted
              and ssys = '$tpsys'"); // arguments, so i made $vars
              if (mysql_num_rows ($stresult) <> 1) {
              mysql_query("in sert into mrb_stot ....") // load a new row
              or die("bummer");
              $stresult = mysql_query("se lect * from mrb_stot
              where sbidit = '$tpbidit'
              and ssys = '$tpsys'"); // load result into $stresult
              )
              $subt = mysql_fetch_ass oc($stresult);
              $mysql_free_res ult($stresult);
              getSurf(1, $pipe["psize"], $pipe["pthk"]); // function also includes
              // mysql_query
              $actstr = $pipe["pstr"]; // initialize
              $strbdsf = $actstr * $psfmlt; // $psfmlt returned by getSurf func
              $winssf = $subt["inssf"]; // will add to this work variable
              [/code]

              And is this the line that generates the error?
              [code=php]
              $winssf = $subt["inssf"]; // will add to this work variable
              [/code]
              You are correct, sir. And pardon the exclusion of [code] tags which would have prevented the earlier misunderstandin g -- I will not make that error in the future!! -- Rhys

              Comment

              • rhys
                New Member
                • Nov 2006
                • 25

                #8
                I just noticed another typo -- on line 15 i close the insert function with a } and not a ) so that is not the source of my issues either -- rhys

                Comment

                • pbmods
                  Recognized Expert Expert
                  • Apr 2007
                  • 5821

                  #9
                  Heya Rhys.

                  Something doesn't seem right. 99% of the time, "unexpected T_ENCAPSED_AND WHITESPACE, expecting T_STRING" occurs when you have an array element quoted inside of a string.

                  E.g., this is what causes the error:
                  [code=php]
                  "A string with an illegal $array['quotedIndex'].";
                  [/code]

                  Instead this should be one of:
                  [code=php]
                  "A string with a legal {$array['quotedIndex']}.";
                  "A string with a legal $array[unquotedIndex].";
                  'A string with a legal ' . $array['quotedIndex'] . '.';
                  [/code]

                  I think your code is still missing a quote mark somewhere.

                  Comment

                  • rhys
                    New Member
                    • Nov 2006
                    • 25

                    #10
                    Originally posted by pbmods
                    Heya Rhys.

                    Something doesn't seem right. 99% of the time, "unexpected T_ENCAPSED_AND WHITESPACE, expecting T_STRING" occurs when you have an array element quoted inside of a string.

                    E.g., this is what causes the error:
                    [code=php]
                    "A string with an illegal $array['quotedIndex'].";
                    [/code]

                    Instead this should be one of:
                    [code=php]
                    "A string with a legal {$array['quotedIndex']}.";
                    "A string with a legal $array[unquotedIndex].";
                    'A string with a legal ' . $array['quotedIndex'] . '.';
                    [/code]

                    I think your code is still missing a quote mark somewhere.
                    Thank you for your immediate consideration of my problem. I have reviewed my code more closely, and find no problems within strings such as you speak of. I did experience one of those problems, in a select string, as noted in my example, and i was able to circumvent it by assigning the subscripted variable to a regular variable, which i used in my select statement.

                    The fact that this is a parse error, in a simple assignment instruction, is what makes it particularly interesting -- as noted, a very similar assignment apparently works, 2 lines earlier. This is what led me to believe i am not referring to the data i think i am, that i have confused the query/result set gods. I continue to look for problems in my strings, and thank you again for your immediate attention!! -- Rhys

                    Comment

                    • entertainmentliveuk
                      New Member
                      • Aug 2007
                      • 9

                      #11
                      [PHP]$stresult = mysql_query("se lect * from mrb_stot
                      where sbidit = '$tpbidit'and ssys = '$tpsys'");
                      // arguments, so i made $vars[/PHP]
                      1. Try removing the comment from inside the mysql_query and change the { to a (

                      Comment

                      • rhys
                        New Member
                        • Nov 2006
                        • 25

                        #12
                        Originally posted by entertainmentli veuk
                        [PHP]$stresult = mysql_query("se lect * from mrb_stot
                        where sbidit = '$tpbidit'and ssys = '$tpsys'");
                        // arguments, so i made $vars[/PHP]
                        1. Try removing the comment from inside the mysql_query and change the { to a (
                        We noticed my {/( issues earlier, and those exist only in the example i (poorly) provided, not my actual code. The comments you note are also only in the example i supplied. But thank you for your attention!! -- Rhys

                        Comment

                        • pbmods
                          Recognized Expert Expert
                          • Apr 2007
                          • 5821

                          #13
                          Heya, Rhys.

                          What does your code look like now? Are you still getting the error on the last line?

                          Comment

                          • Anthony2oo5
                            New Member
                            • Jun 2007
                            • 26

                            #14
                            Can you post the code again without quoteing it in PHP tags so I can copy it to my editor otherwise I have numbers down the side.

                            Comment

                            • pbmods
                              Recognized Expert Expert
                              • Apr 2007
                              • 5821

                              #15
                              Heya, Anthony.

                              Posting without using CODE tags is not allowed in technical forums. However, if you click the Reply button, you can see the code without line numbers.

                              Comment

                              Working...