Link to home
Start Free TrialLog in
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

SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Overthere
Overthere

ASKER

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...
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.
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?
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I got rid of the error but it won't redirect to bldgprofile.php'
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

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! :}
You're welcome, glad to help.