By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

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

P: 25
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("select * from mrb_pipe
where pproj = '$proj'");
while ($pipe = mysql_fetch_assoc($presult)) {
$tpbidit = $pipe["pbidit"];
$tpsys = $pipe["psys"];
$stresult = mysql_query{"select * 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("insert into mrb_stot ....) // load a new row
or die("bummer");
$stresult = mysql_query("select * from mrb_stot
where sbidit = '$tpbidit'
and ssys = '$tpsys'"); // load result into $stresult
)
$subt = mysql_fetch_assoc($stresult);
$mysql_free_result($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
Aug 23 '07 #1
Share this Question
Share on Google+
36 Replies


mwasif
Expert 100+
P: 801
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{"select * from mrb_stot
where sbidit = '$tpbidit' // select didn't like subscripted
and ssys = '$tpsys'");[/PHP]
Use '(' instead of '{'
[PHP]$stresult = mysql_query("select * from mrb_stot
where sbidit = '$tpbidit' and ssys = '$tpsys'");[/PHP]
Aug 23 '07 #2

P: 25
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
Aug 23 '07 #3

P: 25
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!!
Aug 23 '07 #4

pbmods
Expert 5K+
P: 5,821
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.
Aug 23 '07 #5

pbmods
Expert 5K+
P: 5,821
Is this what you have now?

Expand|Select|Wrap|Line Numbers
  1. $presult = mysql_query("select * from mrb_pipe
  2.         where pproj = '$proj'");
  3. while ($pipe = mysql_fetch_assoc($presult)) {
  4.         $tpbidit = $pipe["pbidit"];
  5.         $tpsys = $pipe["psys"];
  6.         $stresult = mysql_query{"select * from mrb_stot
  7.                 where sbidit = '$tpbidit'      // select didn't like subscripted
  8.                 and ssys = '$tpsys'");          // arguments, so i made $vars
  9.         if (mysql_num_rows($stresult) <> 1) {
  10.                 mysql_query("insert into mrb_stot ....") // load a new row
  11.                 or die("bummer");
  12.                 $stresult = mysql_query("select * from mrb_stot
  13.                            where sbidit = '$tpbidit'
  14.                            and ssys = '$tpsys'");   // load result into $stresult
  15.                  )
  16.         $subt = mysql_fetch_assoc($stresult);
  17.         $mysql_free_result($stresult);
  18.         getSurf(1, $pipe["psize"], $pipe["pthk"]);  // function also includes
  19.                                                                             // mysql_query
  20.         $actstr = $pipe["pstr"];            // initialize
  21.         $strbdsf = $actstr * $psfmlt;   //  $psfmlt returned by getSurf func
  22.         $winssf = $subt["inssf"];         //  will add to this work variable
  23.  
And is this the line that generates the error?
Expand|Select|Wrap|Line Numbers
  1. $winssf = $subt["inssf"];         //  will add to this work variable
  2.  
Aug 23 '07 #6

P: 25
Is this what you have now?

Expand|Select|Wrap|Line Numbers
  1. $presult = mysql_query("select * from mrb_pipe
  2.         where pproj = '$proj'");
  3. while ($pipe = mysql_fetch_assoc($presult)) {
  4.         $tpbidit = $pipe["pbidit"];
  5.         $tpsys = $pipe["psys"];
  6.         $stresult = mysql_query{"select * from mrb_stot
  7.                 where sbidit = '$tpbidit'      // select didn't like subscripted
  8.                 and ssys = '$tpsys'");          // arguments, so i made $vars
  9.         if (mysql_num_rows($stresult) <> 1) {
  10.                 mysql_query("insert into mrb_stot ....") // load a new row
  11.                 or die("bummer");
  12.                 $stresult = mysql_query("select * from mrb_stot
  13.                            where sbidit = '$tpbidit'
  14.                            and ssys = '$tpsys'");   // load result into $stresult
  15.                  )
  16.         $subt = mysql_fetch_assoc($stresult);
  17.         $mysql_free_result($stresult);
  18.         getSurf(1, $pipe["psize"], $pipe["pthk"]);  // function also includes
  19.                                                                             // mysql_query
  20.         $actstr = $pipe["pstr"];            // initialize
  21.         $strbdsf = $actstr * $psfmlt;   //  $psfmlt returned by getSurf func
  22.         $winssf = $subt["inssf"];         //  will add to this work variable
  23.  
And is this the line that generates the error?
Expand|Select|Wrap|Line Numbers
  1. $winssf = $subt["inssf"];         //  will add to this work variable
  2.  
You are correct, sir. And pardon the exclusion of [code] tags which would have prevented the earlier misunderstanding -- I will not make that error in the future!! -- Rhys
Aug 23 '07 #7

P: 25
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
Aug 23 '07 #8

pbmods
Expert 5K+
P: 5,821
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:
Expand|Select|Wrap|Line Numbers
  1. "A string with an illegal $array['quotedIndex'].";
  2.  
Instead this should be one of:
Expand|Select|Wrap|Line Numbers
  1. "A string with a legal {$array['quotedIndex']}.";
  2. "A string with a legal $array[unquotedIndex].";
  3. 'A string with a legal ' . $array['quotedIndex'] . '.';
  4.  
I think your code is still missing a quote mark somewhere.
Aug 23 '07 #9

P: 25
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:
Expand|Select|Wrap|Line Numbers
  1. "A string with an illegal $array['quotedIndex'].";
  2.  
Instead this should be one of:
Expand|Select|Wrap|Line Numbers
  1. "A string with a legal {$array['quotedIndex']}.";
  2. "A string with a legal $array[unquotedIndex].";
  3. 'A string with a legal ' . $array['quotedIndex'] . '.';
  4.  
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
Aug 23 '07 #10

entertainmentliveuk
P: 9
[PHP]$stresult = mysql_query("select * 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 (
Aug 23 '07 #11

P: 25
[PHP]$stresult = mysql_query("select * 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
Aug 24 '07 #12

pbmods
Expert 5K+
P: 5,821
Heya, Rhys.

What does your code look like now? Are you still getting the error on the last line?
Aug 24 '07 #13

P: 26
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.
Aug 24 '07 #14

pbmods
Expert 5K+
P: 5,821
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.
Aug 24 '07 #15

P: 25
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.
You guys are the greatest!! I guess I have friends I don't even know.

The problem still exists -- I have found no string issues in my code yet -- and it's not caused by comments only present in my example.

I will post another version of the problem code, without code tags to confuse editors, and most carefully, so as to avoid pesky typos!! This sample will be slightly more complete too.

Expand|Select|Wrap|Line Numbers
  1. $presult = mysql_query("select * from mrb_pipe
  2.         where pproj = '$proj'");
  3. while ($pipe = mysql_fetch_assoc($presult)) {
  4.         if ($pipe["pins"] == "N") break;
  5.         $tpbidit = $pipe["pbidit"];
  6.         $tpsys = $pipe["psys"];
  7.         $stresult = mysql_query("select * from mrb_stot
  8.                 where sbidit = '$tpbidit'
  9.                 and ssys = '$tpsys'");
  10.         if (mysql_num_rows <> 1) {
  11.                 mysql_query("insert into mrb_stot (sbidit,
  12.                 ssys, inssf, inslf, imatl, ilab, imhs,
  13.                 mmatl, mlab, mmhs, sexp, slab, smhs) values
  14.                 ('$tpbidit', '$tpsys', 0.0, 0.0, 0.0, 0.0,
  15.                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)")
  16.                 or die("subttl no workie");
  17.                 $stresult = mysql_query("select * from mrb_stot
  18.                         where sbidit = '$tpbidit'
  19.                         and ssys = '$tpsys'");
  20.                 $ttlmhs = 0.0;
  21.                 }
  22.         $subt = mysql_fetch_assoc($stresult);
  23.         mysql_free_result($stresult);
  24.         getSurf(1, $pipe["psize"], $pipe["pthk"]);
  25.         $actstr = $pipe["pstr"];
  26.         $strbdsf = $actstr * $psfmlt;
  27.         $winssf = $subt["inssf"];
[Added CODE tags for readability. To view the source code without line numbers, click the 'Reply' button. Thanks! -- pbmods]

At this point -- the last line -- is when I get the T_ENCAPSED_ parse error. It makes it through all the previous code. I'd put more error-checking in, but I've got to clear the parser first!!

Thank you again for your indulgence, and please pardon my occasional absence -- gotta make the donuts. I hope your eyes are sharper than mine!! -- Rhys
Aug 24 '07 #16

P: 25
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.
Dang it, i provided a tagless sample -- AGAIN -- as requested -- BEFORE i saw this post. Rest assured I reviewed my code closely first, I WON'T do it again, and please forgive this old newbie!! -- Rhys
Aug 24 '07 #17

pbmods
Expert 5K+
P: 5,821
Heya, Rhys.

Don't worry about it. This is an unusual case.

You got me stumped. My first impulse is that you missed a quote somewhere before the snippet you posted, except then you should have gotten this error before the last line of your code.

I hate to ask an obvious question, but I just need to make sure. The line number referenced in the error code definitely matches up with the last line that you posted, correct?
Aug 24 '07 #18

P: 25
Heya, Rhys.

Don't worry about it. This is an unusual case.

You got me stumped. My first impulse is that you missed a quote somewhere before the snippet you posted, except then you should have gotten this error before the last line of your code.

I hate to ask an obvious question, but I just need to make sure. The line number referenced in the error code definitely matches up with the last line that you posted, correct?
I checked that specifically. insert a blank line above it, it moves down. Take that blank line out and insert a blank line below it, it is the same. Were it a later line it would stay the larger value. i have pored over the getSurf function it calls shortly before this, to see if anything amiss there -- not apparently.

It's a Doozie all right!! They'll call it the Rhys Bug. Old school meets Hi Tek. Thx again for your attention!! -- Rhys
Aug 24 '07 #19

P: 25
Heya, Rhys.

Don't worry about it. This is an unusual case.

You got me stumped. My first impulse is that you missed a quote somewhere before the snippet you posted, except then you should have gotten this error before the last line of your code.

I hate to ask an obvious question, but I just need to make sure. The line number referenced in the error code definitely matches up with the last line that you posted, correct?
I hope i haven't lost your interest. This puzzle continues to vex me. I try to think of alternative approaches, but really need to do it this way, i think.

I guess i don't seek a specific solution to this particular problem, as much as an answer to a more general question: Am i violating any basic tenets or precepts of MySQL by structuring my queries and result sets such that i have? I had hoped to have the result sets of several queries available at any given time, and maybe the problem has to do with my assignment of variables. At any rate, this parse error makes little sense to me, in its specific location.

Another question arises: Does the parser process the source sequentially, or does it parse functions as they are encountered? The reason I ask is, it doesn't complain about a variable returned from a function and previously unreferenced, yet another previous function (Init()) contains math calculations involving subscripted(table element) arguments which I thought illegal. If the parser saw these, it should have coughed. This could make a difference in my debugging approach.

I really hope this turns out to be a simple syntax or assignment issue, and not a fundamental flaw in my logic and its feasibility with MySQL. I wait with bated breath, for any solutions or suggestions, if anyone is still interested. In the meantime, I won't quit my night job!!

I thank any and all for their time and attention!! -- Rhys
Aug 25 '07 #20

pbmods
Expert 5K+
P: 5,821
Heya, Rhys.

When PHP prepares to execute a script, the first thing it does is run through and parse the script to make sure that there are no syntax errors. This scan is sequential, so if an error is detected, the parser stops and reports the line number. Note that an error's 'location' (within a function, class method, etc.) is unimportant because the parser is merely running through line-by-line to check your syntax.

There are run-time errors that can occur that can not be readily detected via a syntax check, but your script is not getting any of those.

It is important to note that until the syntax error is fixed, your script never gets executed, so you can rule out any MySQL-related problems right now because your script never actually connects to the MySQL database server.

Are you using eval() anywhere in your script? Are you sure that you are looking at the correct file? If you comment out the line that causes the error, what happens?
Aug 25 '07 #21

P: 25
Heya, Rhys.

When PHP prepares to execute a script, the first thing it does is run through and parse the script to make sure that there are no syntax errors. This scan is sequential, so if an error is detected, the parser stops and reports the line number. Note that an error's 'location' (within a function, class method, etc.) is unimportant because the parser is merely running through line-by-line to check your syntax.

There are run-time errors that can occur that can not be readily detected via a syntax check, but your script is not getting any of those.

It is important to note that until the syntax error is fixed, your script never gets executed, so you can rule out any MySQL-related problems right now because your script never actually connects to the MySQL database server.

Are you using eval() anywhere in your script? Are you sure that you are looking at the correct file? If you comment out the line that causes the error, what happens?
Thanks again for caring!! Here is what I have discovered:

I think my current-result-set suspicions have some merit... I found that when i move all references to the first result set -- $pipe -- to occur before the second -- $subt -- happens, store them in regular variables for later use, then subsequent assignment of subscripted mysql table elements to regular $variables works, as long as it is the current result set. The assignment command which failed worked just fine, in its same syntax, once I moved all references to the previous result set back outside the current query result. Now I'm not sure if my failed math commands and function calls containing subscripted elements failed because it didn't like the subscripts, or it just wasn't the current result set. Maybe the latter, but I have replaced those references with $variables which work, and more research is necessary.

The point is moot, at the moment. I think I have discovered the essence of my woes, and discovered how to deal with it. Thank you for reassuring me it was not a mysql bug, and piquing my curiosity enough to try different approaches. I hope to not pollute this fine forum with my trivia again, but it is reassuring to know it's here. Thanks again for your time and concern!! -- Rhys
Aug 26 '07 #22

pbmods
Expert 5K+
P: 5,821
Heya, Rhys.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 26 '07 #23

P: 25
Thanks again for caring!! Here is what I have discovered:

I think my current-result-set suspicions have some merit... I found that when i move all references to the first result set -- $pipe -- to occur before the second -- $subt -- happens, store them in regular variables for later use, then subsequent assignment of subscripted mysql table elements to regular $variables works, as long as it is the current result set. The assignment command which failed worked just fine, in its same syntax, once I moved all references to the previous result set back outside the current query result. Now I'm not sure if my failed math commands and function calls containing subscripted elements failed because it didn't like the subscripts, or it just wasn't the current result set. Maybe the latter, but I have replaced those references with $variables which work, and more research is necessary.

The point is moot, at the moment. I think I have discovered the essence of my woes, and discovered how to deal with it. Thank you for reassuring me it was not a mysql bug, and piquing my curiosity enough to try different approaches. I hope to not pollute this fine forum with my trivia again, but it is reassuring to know it's here. Thanks again for your time and concern!! -- Rhys
These are my first real forays into PHP and MySQL with my real database -- formerly PostGreSQL, formerly C-ISAM -- after the tests had me convinced I knew what I was doing. Obviously I have some of the nuances yet to learn. And I'm sure the way I nest my queries belies my old-school background.

I have yet to make it through the parser, waited until it grew too large to try. But I'm learning!! And there's lots more of this program to come, but I thought I'd clean this up first. And it doesn't parse yet, though hopefully its remaining issues are well in hand.

Even when it parses, as you point out, that is no guarantee of proper - or desired - execution. I'm just hoping I haven't offended the MySQL gods too much, and that the main "while" loop -- dependent on the first result set -- has not gotten confused by the intervening query/results. "Endless Loop" time? I'll design my future tests to test that theory, but I've got some coding to do first.

In the meantime I'm off to the races, with your help and encouragement. Thank you again and again!! -- Rhys
Aug 26 '07 #24

P: 25
These are my first real forays into PHP and MySQL with my real database -- formerly PostGreSQL, formerly C-ISAM -- after the tests had me convinced I knew what I was doing. Obviously I have some of the nuances yet to learn. And I'm sure the way I nest my queries belies my old-school background.

I have yet to make it through the parser, waited until it grew too large to try. But I'm learning!! And there's lots more of this program to come, but I thought I'd clean this up first. And it doesn't parse yet, though hopefully its remaining issues are well in hand.

Even when it parses, as you point out, that is no guarantee of proper - or desired - execution. I'm just hoping I haven't offended the MySQL gods too much, and that the main "while" loop -- dependent on the first result set -- has not gotten confused by the intervening query/results. "Endless Loop" time? I'll design my future tests to test that theory, but I've got some coding to do first.

In the meantime I'm off to the races, with your help and encouragement. Thank you again and again!! -- Rhys
Oh yeah -- a confusing aspect of this problem was its manifestation: calls to prior result sets worked, even in a new result set, but then calls to the current result set failed. Only when prior calls to the senior result set were moved outside the current result set, did calls to it work. Interesting, eh?
Aug 26 '07 #25

P: 25
Oh yeah -- a confusing aspect of this problem was its manifestation: calls to prior result sets worked, even in a new result set, but then calls to the current result set failed. Only when prior calls to the senior result set were moved outside the current result set, did calls to it work. Interesting, eh?
I SPOKE TOO SOON!! The same parse error has returned. I was moving through my source, where virtually ALL of my parse errors were related to mysql query results, and references to them. I found that the parser did not like subscripted arguments or operands in math instructions, function calls, or switch:case commands. In addition, it appeared that only the current result set was reliably available for reference. I got the parser to make it all the way through my main "while" loop, and it was parsing the first function, when I got ANOTHER of those T_ENCAPSED_AND WHITESPACE parse errors, on the last line of the following:

Expand|Select|Wrap|Line Numbers
  1. $mresult = mysql_query("select * from mrb_matl where
  2.                 mtable = '$mtbl' and msize = '$isiz'");
  3. $price = mysql_fetch_assoc($mresult);
  4. mysql_free_result($mresult);
  5. $wmthk1 = $price["mthk1"];
  6.  
My current-result-set explanation fails this time (and I was so smug). All tables, field names, and variables are valid, the nearest string is 2 lines above, and it is definitely that assignment causing that error. The function is properly called, and passed the right number of variables... I'm stumped!!

Again I must voice a concern -- that my old-time logic has revealed a deficiency in the PHP parser, relating to multiple mysql result sets, and I can't do what I need to do!! Not in this fashion, at least. In the current instance, I need to pre-load some regular $variables with mysql table row elements, because the switch:case coming up doesn't like them there!!

Did I do my [code] tags right?

I will be happy to provide any interested parties all the detail they desire. And thank you again for your indulgence!! -- Rhys
Aug 27 '07 #26

P: 25
I SPOKE TOO SOON!! The same parse error has returned. I was moving through my source, where virtually ALL of my parse errors were related to mysql query results, and references to them. I found that the parser did not like subscripted arguments or operands in math instructions, function calls, or switch:case commands. In addition, it appeared that only the current result set was reliably available for reference. I got the parser to make it all the way through my main "while" loop, and it was parsing the first function, when I got ANOTHER of those T_ENCAPSED_AND WHITESPACE parse errors, on the last line of the following:

Expand|Select|Wrap|Line Numbers
  1. $mresult = mysql_query("select * from mrb_matl where
  2.                 mtable = '$mtbl' and msize = '$isiz'");
  3. $price = mysql_fetch_assoc($mresult);
  4. mysql_free_result($mresult);
  5. $wmthk1 = $price["mthk1"];
  6.  
My current-result-set explanation fails this time (and I was so smug). All tables, field names, and variables are valid, the nearest string is 2 lines above, and it is definitely that assignment causing that error. The function is properly called, and passed the right number of variables... I'm stumped!!

Again I must voice a concern -- that my old-time logic has revealed a deficiency in the PHP parser, relating to multiple mysql result sets, and I can't do what I need to do!! Not in this fashion, at least. In the current instance, I need to pre-load some regular $variables with mysql table row elements, because the switch:case coming up doesn't like them there!!

Did I do my [code] tags right?

I will be happy to provide any interested parties all the detail they desire. And thank you again for your indulgence!! -- Rhys
!!False Alarm!! Sort of... I found that if I replaced the [] around subscript names with () it WORKS!! Parses at least... There's one for the manual... but then, how did the previous []'s -- and there were many -- work? And why not now? I'm just a guppy in this ocean, and this is scary!! -- Rhys
Aug 27 '07 #27

pbmods
Expert 5K+
P: 5,821
Heya, Rhys.

What version of PHP are you running?
Aug 27 '07 #28

P: 25
Heya, Rhys.

What version of PHP are you running?
I'm running PHP 5.1.6, mysql Ver 14.12 Distrib 5.0.24a, and Ubuntu 2.6.17-10.34-generic
Aug 27 '07 #29

pbmods
Expert 5K+
P: 5,821
Heya, Rhys.

Weird.

I was thinking that maybe PHP thought that $price was a string, and earlier versions of PHP don't allow you to access an index of a string using array-style brackets.

Except that wouldn't generate a parse error, and mysql_fetch_assoc() never returns a string. And PHP 5 doesn't have the string index syntax problem anyway.

Ah well.
Aug 27 '07 #30

P: 25
Heya, Rhys.

Weird.

I was thinking that maybe PHP thought that $price was a string, and earlier versions of PHP don't allow you to access an index of a string using array-style brackets.

Except that wouldn't generate a parse error, and mysql_fetch_assoc() never returns a string. And PHP 5 doesn't have the string index syntax problem anyway.

Ah well.
Yeah weird. I got it to successfully parse -- ALMOST -- by replacing the remaining brackets with parens. Now I'm getting a parse error -- "unexpected $end in..." the line past my end. My last line is </html> on line 343, and this error occurs on line 344. It has me poring over my code again, looking for a {} or [] or "" mismatch, as yet unsuccessfully, and i'm wondering if i have other structure issues, with my html or something. Researching that now. I guess i can confuse a parser, huh. My application, though voluminous and will get way more so, is not all that complex or hard to decipher. Maybe I should go back and replace previous []'s which worked (apparently) with () and see if they still parse. Like my ex-guru, 3 gurus ago, said: If it was easy, everybody would do it. Thanks for your interest!! -- Rhys
Aug 27 '07 #31

pbmods
Expert 5K+
P: 5,821
Heya, Rhys.

Couple of thoughts.
  • Do you have any 'gremlins' in your code (non-printable characters)? You oftentimes will get these when copying code from a website. I know that BBEdit is really good at zapping gremlins, but that's the extent of my experience.
  • Do you have any kind of a quote mismatch somewhere in your code? Perhaps you opened a quote with a ' but closed it with a " or vice versa? Does your editor use syntax highlighting?
  • Did you close a PHP block but forget to open it again or vice versa? For example:
    Expand|Select|Wrap|Line Numbers
    1. <?php
    2.     if( {condition} )
    3.     {
    4. ?>
    5.     <div>
    6.         Output some HTML because {condition} is true!
    7.     </div>
    8.  
    9.         // Oops.... forgot something!
    10.     }
    11.  
  • Did you open a comment block but forget to close it? E.g.,:
    Expand|Select|Wrap|Line Numbers
    1. if( {condition} )
    2. {
    3.     /*
    4.     I changed my mind; I don't want this code to execute.
    5.     $_res = mysql_query( ... );
    6.     $_row = mysql_fetch_assoc($_res);
    7.     mysql_free_result($_res);
    8. }
    9.     /*
    10.         I'd rather do this instead....
    11.     */
    12.     mysql_query( ... );
    13.  

If it sounds like I'm grasping at straws, well....

You may want to ZIP your source files and attach them ('attach' is available when you are editing a post) so that we can look at the entire script.
Aug 27 '07 #32

P: 25
Heya, Rhys.

Couple of thoughts.
  • Do you have any 'gremlins' in your code (non-printable characters)? You oftentimes will get these when copying code from a website. I know that BBEdit is really good at zapping gremlins, but that's the extent of my experience.
  • Do you have any kind of a quote mismatch somewhere in your code? Perhaps you opened a quote with a ' but closed it with a " or vice versa? Does your editor use syntax highlighting?
  • Did you close a PHP block but forget to open it again or vice versa? For example:
    Expand|Select|Wrap|Line Numbers
    1. <?php
    2.     if( {condition} )
    3.     {
    4. ?>
    5.     <div>
    6.         Output some HTML because {condition} is true!
    7.     </div>
    8.  
    9.         // Oops.... forgot something!
    10.     }
    11.  
  • Did you open a comment block but forget to close it? E.g.,:
    Expand|Select|Wrap|Line Numbers
    1. if( {condition} )
    2. {
    3.     /*
    4.     I changed my mind; I don't want this code to execute.
    5.     $_res = mysql_query( ... );
    6.     $_row = mysql_fetch_assoc($_res);
    7.     mysql_free_result($_res);
    8. }
    9.     /*
    10.         I'd rather do this instead....
    11.     */
    12.     mysql_query( ... );
    13.  

If it sounds like I'm grasping at straws, well....

You may want to ZIP your source files and attach them ('attach' is available when you are editing a post) so that we can look at the entire script.
I reviewed my code more closely, and found a couple of minor issues, but nothing which affected this error. I moved my html around, though it is scarcely necessary for this program, also with no effect.

I zipped up that file, and I must be the dumbest guy in town, because I can't see where to attach it to this. All tips welcome. Thx again!! --

Found it!!
Rhys
Attached Files
File Type: zip crunch.zip (2.2 KB, 86 views)
Aug 28 '07 #33

pbmods
Expert 5K+
P: 5,821
Heya, Rhys.

On line 65, you have a misplaced backtick.
Aug 28 '07 #34

P: 25
Heya, Rhys.

On line 65, you have a misplaced backtick.
Well, skin me alive!! I DIDN'T EVEN SEE IT!! Even when you pointed it out -- my editor showed 65 to be the line above -- I STILL had a hard time finding it. I won't blame the tiny screen on my development laptop, or its 640x480 resolution, or my bifocals, which are obviously not progressive enough. Or the propensity for the human brain -- or at least mine -- to subconsciously ignore what it does not fathom. But your idea of a syntax-highlighting editor has much merit at this point. I've been using vi forever. Can you suggest a similar editor, preferably open-source, which highlights code?

I have no idea how or when that got in there, let alone why. Maybe the cat did it. And the parser!! You would've thought, after a while, it'd know I didn't mean that!! I mean c'mon, enough is enough, right? Ha!! Computers aren't smart -- they're just fast.

All kidding aside, I'm sure the parser probably took everything it saw, after that `, as a string, in lieu of an opposing `, and complained about string violations. I went through last night, after fixing that, and unfixed a lot of stuff, no longer necessary, and changed the rest back to proper [] format. And it WORKS!! I'm happy to report that I am now successfully updating those pesky subtotals records -- I mean, rows.

I'm sorry I wasted your time with my ignorance and blindness, hope that does not happen again. But thank you again and again for your patience and indulgence; this one was driving me crazy, and I was about to cry or something. And again, any editor suggestions are welcome.

Thank you again, and go in Peace!! -- Rhys
Aug 28 '07 #35

pbmods
Expert 5K+
P: 5,821
Heya, Rhys.

For Mac OS X, Bare Bones Software makes a very nice free app called TextWrangler. For about $80 you can upgrade to their fully-featured (and very much awesome) BBEdit. But TextWrangler by itself is still a fantastic (did I mention free?) app.

[EDIT: Of course, BBEdit does not currently recognize the backtick operator as a string delimiter, so even that would not have helped in this case.]

[EDIT EDIT: You can also set up syntax highlighting in vim. Check out this article.]

And in terms of missing the backtick, I did too, for about half an hour. I finally decided to go in and refactor your code to see if there was whitespace where there shouldn't be any. The first step when I refactor is to remove all indenting, and one line just refused to indent all the way....

The backtick is, incidentally, an operator in PHP. It is equivalent to calling shell_exec() on an equivalent string.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 28 '07 #36

P: 25
Heya, Rhys.

For Mac OS X, Bare Bones Software makes a very nice free app called TextWrangler. For about $80 you can upgrade to their fully-featured (and very much awesome) BBEdit. But TextWrangler by itself is still a fantastic (did I mention free?) app.

[EDIT: Of course, BBEdit does not currently recognize the backtick operator as a string delimiter, so even that would not have helped in this case.]

[EDIT EDIT: You can also set up syntax highlighting in vim. Check out this article.]

And in terms of missing the backtick, I did too, for about half an hour. I finally decided to go in and refactor your code to see if there was whitespace where there shouldn't be any. The first step when I refactor is to remove all indenting, and one line just refused to indent all the way....

The backtick is, incidentally, an operator in PHP. It is equivalent to calling shell_exec() on an equivalent string.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Thank you again!! My local Linux guru begged off on this one, nasty summer cold, but I think my code scared him. That, or he just didn't want to wade through it. Too bad -- he uses a souped-up version of the jed editor, may well have spotted it.

I can't tell you how many times, over the last several years and 2 previous incarnations of this system, I have felt totally alone in this world, on a sea of one, storm raging, no land in sight, no phones to ring.

Your immediate response, and ongoing concern, were a lifesaver this time, Buddy, and I was floundering!! It is this level of concern which insures that Open Source will prevail -- try getting support that fast from Microsoft!!

Long live Open Source, and God Bless you!! -- Rhys
Aug 28 '07 #37

Post your reply

Sign in to post your reply or Sign up for a free account.