David Shields
David Shields

Reputation: 596

Why does my comment with <BR> cause my code to display in browser weirdly with PHP?

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.

Upvotes: 2

Views: 380

Answers (1)

Ali
Ali

Reputation: 267077

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.

Upvotes: 3

Related Questions