We help IT Professionals succeed at work.

Parsing Error when using heredoc

Overthere
Overthere asked
on
78 Views
Last Modified: 2015-12-11
I have a snippet of coding, PHP v5.5, that keeps giving the following error:
Parse error: syntax error, unexpected '<<' (T_SL)

I checked for whitespaces and I have started the coding on a new line after issuing the <<<ONSELECTROW
I can't seem to resolve this parsing error.
Any help appreciated..


               $dg -> set_pagesize(10);
               $dg -> add_event("jqGridSelectRow", $onSelectRow);

               $onSelectRow = <<<ONSELECTROW 
                       function(status,rowid)
                            } 
                               var $bnbr = $('#Buildings').jqGrid('getCell',rowid,'BldNbr');
                               header ('Location: bldgprofile.php' . '?' . '$bnbr=' . BldNbr);
                             }
                        ONSELECTROW;

               $dg->display();   

Open in new window

Comment
Watch Question

gr8gonzoConsultant
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Yes, I did have the curly braces wrong. I corrected them and still no go. Same error message.
Earlier, I did have a error due to a white space, and I corrected it.
And then this current parsing error came up.
 I don't know how I am going to do this. All I want to do is get the row selected, so I can et the BldNbr and go to another page...It shouldn't be this hard...
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
Your code looks like a mix of JavaScript and PHP inside the HEREDOC part.  HEREDOC is a text formatting function and text inside it will not be executed as PHP code.
gr8gonzoConsultant
CERTIFIED EXPERT

Commented:
Dave has a good point about the mixture stuff. I didn't look too much at the contents before, but yeah, that PHP code in there isn't going to work.

Moving on, can you attach the full code file here (don't edit anything except X-ing out any passwords or sensitive info) and provide the full error message with line numbers?

Author

Commented:
here as much as I can post. If I comment out the section of new coding it displays etc. and works well, including the date range selection.
I just added in the new section of coding to be able to know what row the user clicked on so I can grab the BldNbr and move on to the next page.
I am using phpGrid from phpGrid.com and this is the link for their example.
  http://phpgrid.com/example/custom-event-handler/

I don't need the onrowselect2  etc.

   
        $sqlquery = "Select BldNbr,
                               StreetAddress,
                               StreetAddress2,
                               City,
                               State,
                               Country,
                               ZipCode,
                               Status,
                               ChgDate From BuildingMaster";
         
                  $dg = new C_DataGrid($sqlquery,"BldNbr","BuildingMaster"); 
                  $dg-> set_query_filter("ChgDate >= '$begdate'");


                  // new coding for get row user clicked on

                  $dg -> add_event("jqGridSelectRow", $onSelectRow);
 
                  $onSelectRow = <<<ONSELECTROW 
                       function(status,rowid)
      
                             } 
                                   console.log(rowid);
                                   console.log(status);
                                   bnbr = $('#BuildingMaster').jqGrid('getCell',rowid,'BldNbr');
                                   header ('Location: bldgprofile.php' . '?' . 'bnbr=' . BldNbr);
                             }
                        ONSELECTROW;
                   // end of new coding for row selected


                   $dg -> set_pagesize(10);
                   $dg->display();   

Open in new window

Fixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I got rid of the error but it won't redirect to bldgprofile.php'
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
No and it's not going to.  'header ()' is a PHP function, not a JavaScript function.  PHP functions don't run inside a HEREDOC block.  And they don't run in the browser either.  If you look at the original example, you will see that they are using the javascript method.
window.location = encodeURI("http://example.com/" + "?" + "orderNumber=" + orderNumber 

Open in new window

Author

Commented:
You're right David, I didn't use the same code. I had read the document at the link prior to my initial posting, because I wasn't quite sure what "heredocs' were about etc. I had just a vague idea.  One would think they post an example correctly... their example does pop up an alert window and naturally since they commented out the redirects etc, that would be correct.
But you would THINK they would ahere to the "structure" rules.
Well, I learn an a great deal and even though its been time consuming, its been worth it. I appreciate all your input and guidance.
And thank you too gr8gonzo!
I did succeed it making it work, but it's real touchy and would like to find a better way of coding it....
thanks folks! :}
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
You're welcome, glad to help.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.