Avatar of Overthere
Overthere asked on

Parsing Error when using heredoc

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

PHP

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
SOLUTION
gr8gonzo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Overthere

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 Baldwin

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.
gr8gonzo

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?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
Overthere

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

ASKER CERTIFIED SOLUTION
Dave Baldwin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Overthere

I got rid of the error but it won't redirect to bldgprofile.php'
Dave Baldwin

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

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Overthere

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 Baldwin

You're welcome, glad to help.