473,581 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

25 New Member
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
Aug 23 '07 #1
36 7980
mwasif
802 Recognized Expert Contributor
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]
Aug 23 '07 #2
rhys
25 New Member
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
rhys
25 New Member
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
5,821 Recognized Expert Expert
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
5,821 Recognized Expert Expert
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
rhys
25 New Member
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 misunderstandin g -- I will not make that error in the future!! -- Rhys
Aug 23 '07 #7
rhys
25 New Member
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
5,821 Recognized Expert Expert
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
rhys
25 New Member
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

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

Similar topics

2
2879
by: Salim | last post by:
Hi people, keep getting this errorParse error: parse error, unexpected T_STRING in order_fns.php line 91. the code is below for the file and I've indicated line 91 <?php function process_card($card_details) { // connect to payment gateway or // use gpg to encrypt and mail or // store in DB if you really want to
5
13144
by: Anna MZ | last post by:
I am new to php and have written the following mysql code to enter the details of a new user in the admin subdomain of my website: $sql = "INSERT INTO 'users' ('userid', 'username', 'upassword') VALUES ('$_POST', '$_POST', '$_POST') mysql_query($sql)"; When I view the code in Internet Explorer I get the following error message: ...
4
22141
kestrel
by: kestrel | last post by:
I have some html code that is supposed to be displayed by php echo. But for some reason i keep getting a syntax error, and i cant figure out what is going on. Heres what i have <?php if(isset($_GET)) { echo "<div id="visible">"; echo "<span onclick="swapform()">Log In Form</span>"; echo "</div>"; echo "<div id="theform"...
3
2391
by: sclarkstone | last post by:
Im getting this error; Parse error: syntax error, unexpected T_STRING, expecting ':' or ';' with this line; header ('postcodesearch.php?e=nw&pcode=',); I cant find whats wrong, can anyone help?
2
3211
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString", $formName); // 06-22-07 - the next commands try to import all the functions that the
2
3234
by: fburn | last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux. I receive an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/inventoryControl/supplier.php on line 26 (line number changed to match code tags) The code is as follows: ...
3
5591
paulrajj
by: paulrajj | last post by:
hi to all, i am getting syntax error on my code.. Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\xampp\htdocs\Dummy\paulraj\matrim\exam.php on line 62 what's the actual problem here..? my code
10
5638
by: benicio | last post by:
Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\wamp\www\study_group\includes\functions.php on line 19 I got this error and this syntax is from 8 to 19th line. <?php $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)) { echo...
14
5493
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up all the rows which have the corresponding state. I am getting this 'Parse error: syntax error, unexpected T_STRING in /home/attorney/public_html/' on...
0
7792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8175
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6553
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5674
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1138
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.