tags:

views:

208

answers:

1

Since when did:

//echo "[$sql][$result][$rows][$e]<BR>";

cause an error? The code following this comment gets spwewed out as source in the browser! Bear in mind I use php daily, I've never seen this before! I'm porting an ancient php app from an old Win2k box to a new Windoze 2003 server - apache 2.2, mysql 5.1.32, php 5.2.9, and the app is bombing all over the place cos there's commented out code everywhere. Any switches to stop it being so sensitive to comments? I know // followed by ?> then code will break as ?> terminates the php, but BR tags ? Surely not.

More details: The code chunk is

if ($condition){
  // do stuff
} else {
  $sql="select * from person where percode='$person'";
  $result=mysql_db_query($db,$sql,$conn);
  @$rows=mysql_num_rows($result);
  $e=mysql_errno()." ".mysql_error();
  //echo "[$sql][$result][$rows][$e]<br>";
  $perfname=mysql_result($result,0,"perfname");
  $persname=mysql_result($result,0,"persname");
  $peraddr1=mysql_result($result,0,"peraddr1");
}
?>

The code up to the comment runs fine. The code after the comment up to the ?> is vomited out into the browser. After that, the HTML display is fine. Remove comment (or even just the < and > around the BR makes code work just fine.

+3  A: 

You could have the short open tag setting turned off in the php.ini file of the new server you are moving to. If this setting is turned off, all of your <? tags are ignored and only code between the full

<?php and ?> tags is parsed as PHP code. See if that setting is turned off and if turning it on fixes it.

If not, check if you're mistakenly doing '?> anywhere before the comments. Also, sharing the full code block will help.

Click Upvote
short_open_tag = Off in php.ini, but I *always* use <?php. This app has been working fine on old platform for about 6 years.
WaveyDavey
Aaaargh - seppuku time! Just spotted a <? rather than a <?php tag at start of code block.Sheesh! What an eejit.
WaveyDavey
Ok, smart people - what regexp to find <?[NOT php string tag!
WaveyDavey
You can upvote and click the checkbox near the answer to accept it if you want
Click Upvote
Lol, make that a separate question, but why not just turn on the short_open_tag setting so <? tags work? it would be easier
Click Upvote