PHP Displays in Plain Text

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP Displays in Plain Text

Postby rquaid.pro » 01. September 2010 09:21

I feel like such a n00b. ;P

I was writing some PHP files earlier and everything was working fine. I closed out my browser windows and Notepad++ and walked away from the computer for a while. Now, whenever I open a .php file in FF, it treats it like a .htm file, dumping some of the PHP code to the screen. Also, if I "View Source" in the browser, it shows all of the PHP code.

I was Googling around but the only solution that I found was to add a line to the httpd.conf file, but that didn't seem right. After all, the code was working fine earlier without any changes to the .conf file. Also, it appeared that that was a solution to get .htm files to be parsed with the PHP interpreter instead of giving them the .php extension.

Thinking something with XAMPP or Apache just bailed, I rebooted the server but that didn't help at all. Also, looking in the XAMPP Admin window it shows PHP as being activated.

I can't figure out why, but the PHP interpreter just doesn't seem to want to work. Here's the code from the file:

Code: Select all
<?php

mysql_connect('*********', '****', '******');
mysql_select_db('char_page');

function build_character_array() {
   $char_array = "var characterArray = new Array();";
   $nbr_of_chars = get_table_data('COUNT(char_nbr)', 'characters', false);
   for ($i = 0; $i < $nbr_of_chars; $i++) {
      $char_array .= "\ncharacterArray[" . $i . "] = new character(";
      $char_array .= '"' . get_table_data('name', 'characters', 'char_nbr = "' . $i . '"') . "\", ";
      $char_array .= '"' . get_table_data('clan', 'characters', 'char_nbr = "' . $i . '"') . "\", ";
      $char_array .= get_table_data('city_stat', 'characters', 'char_nbr = "' . $i . '"') . ", ";
      $char_array .= get_table_data('anar_stat', 'characters', 'char_nbr = "' . $i . '"') . ", ";
      $char_array .= get_table_data('cama_stat', 'characters', 'char_nbr = "' . $i . '"') . ", ";
      $char_array .= get_table_data('sabb_stat', 'characters', 'char_nbr = "' . $i . '"') . ", ";
      $char_array .= '"' . get_table_data('office', 'characters', 'char_nbr = "' . $i . '"') . "\", ";
      $char_array .= get_table_data('npc', 'characters', 'char_nbr = "' . $i . '"') . ", ";
      $char_array .= get_table_data('founder', 'characters', 'char_nbr = "' . $i . '"') . ", ";
      $char_array .= get_table_data('triumvir', 'characters', 'char_nbr = "' . $i . '"') . ", ";
      $char_array .= get_table_data('council', 'characters', 'char_nbr = "' . $i . '"') . ", ";
      $char_array .= get_table_data('mgd', 'characters', 'char_nbr = "' . $i . '"') . ", ";
      $char_array .= '"' . get_table_data('pic', 'characters', 'char_nbr = "' . $i . '"') . "\", ";
      $char_array .= '"' . get_table_data('bio', 'characters', 'char_nbr = "' . $i . '"') . "\");";
   }
   
      return $char_array;
}

function get_table_data($field, $table, $where) {
   $statement = "SELECT " . $field . " FROM " . $table;
   if ($where)
      $statement .= " WHERE " . $where;
   $statement .= ";";
   $query = mysql_query($statement) or die("<b>A fatal MySQL error has occured while processing Query:</b>\n" . $statement . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());;
   $row = mysql_fetch_array($query);
   
      return $row[$field];
}

?>

<html>
<head>
<meta="author" content="Richard W. Quaid">
<meta="description" content="This page displays characters from the KC Sunshine LARP including bios and other stats.">
<title>KC Sunshine LARP Characters Page</title>
<link rel="stylesheet" href="kc.css" type="text/css" />

<style type="text/css">

.noBox {
   border: 0;
   background-color: transparent;
}

</style>

<script type="text/javascript" language="javascript">

function character(name, clan, cityStatus, anarchStatus, camarillaStatus, sabbatStatus, office, npc, founder, triumvirate, council, mgd, pic, bio) {
   this.name = name;
   this.clan = clan;
   this.cityStatus = cityStatus;
   this.anarchStatus = anarchStatus;
   this.camarillaStatus = camarillaStatus;
   this.sabbatStatus = sabbatStatus;
   this.office = office;
   this.npc = npc;
   this.founder = founder;
   this.triumvirate = triumvirate;
   this.council = council;
   this.mgd = mgd;
   this.pic = pic;
   this.bio = bio;
}

<?php echo build_character_array() ?>

function displayCharacters() {
   var newHTML = "";
   for (var i = 0; i < characterArray.length; i++) {
      newHTML += "<div height=\"180\">";
      if (i == 0 || i % 2 == 0) {
         newHTML += "<img src=\"graphics/charPics/" + characterArray[i].pic + "\" style=\"float: left; padding-right: 15px;\" height=\"180\" width=\"142\" />\n";
         newHTML += "<img src=\"graphics/" + characterArray[i].clan + ".gif\" style=\"float: right;\" />\n";
      }
      else {
         newHTML += "<img src=\"graphics/charPics/" + characterArray[i].pic + "\" style=\"float: right; padding-right: 15px;\" height=\"180\" width=\"142\" />\n";
         newHTML += "<img src=\"graphics/" + characterArray[i].clan + ".gif\" style=\"float: left;\" />\n";
      }
      newHTML += "<h2>" + characterArray[i].name + "</h2>\n";
//      newHTML += "<h3>" + characterArray[i].sect.substr(0,1).toUpperCase() + characterArray[i].sect.substr(1);
      if (characterArray[i].office != "")
         newHTML += " " + characterArray[i].office;
      newHTML += ", City Status: " + characterArray[i].cityStatus + "</h3>\n";
      newHTML += "<p>" + characterArray[i].bio + "</p>\n";
      newHTML += "<p align=\"center\">";
      if (characterArray[i].npc)
         newHTML += "<b>NPC</b>";
      else
         newHTML += "<span style=\"text-decoration: line-through;\">NPC</span>";
      newHTML += "&nbsp;";
      if (characterArray[i].founder)
         newHTML += "<b>FPC</b>";
      else
         newHTML += "<span style=\"text-decoration: line-through;\">FPC</span>";
      newHTML += "&nbsp;";
      if (characterArray[i].triumvirate)
         newHTML += "<b>Triumvirate</b>";
      else
         newHTML += "<span style=\"text-decoration: line-through;\">Triumvirate</span>";
      newHTML += "&nbsp;";
      if (characterArray[i].council)
         newHTML += "<b>Council</b>";
      else
         newHTML += "<span style=\"text-decoration: line-through;\">Council</span>";
      newHTML += "&nbsp;";
      if (characterArray[i].mgd)
         newHTML += "<b>MGD</b>";
      else
         newHTML += "<span style=\"text-decoration: line-through;\">MGD</span>";
      newHTML += "</div><br />";
   }
   
      document.getElementById('characterDisplay').innerHTML = newHTML;
}

</script>
</head>

<body background="graphics/body.jpg" style="background-attachment: fixed;" onload="displayCharacters()">

<div class="banner"><img src="graphics/CBanner.jpg" class="centered"></div>
<br />
<div id="characterDisplay" class="noBox">&nbsp;</div>
<br />
<div id="adminTools"><a href="char_reset.php">Reset Characters Database</a></div>

</body>
</html>


This...
"A fatal MySQL error has occured while processing Query:\n" . $statement . "
\nError: (" . mysql_errno() . ") " . mysql_error());; $row = mysql_fetch_array($query); return $row[$field]; } ?>"
...is what shows up at the top of the page when it's loaded.

Thanks in advance to anyone who can shed some light on this.

-Quaid
rquaid.pro
 
Posts: 4
Joined: 01. September 2010 09:04

Re: PHP Displays in Plain Text

Postby Nobbie » 01. September 2010 09:50

rquaid.pro wrote: Now, whenever I open a .php file in FF, it treats it like a .htm file, dumping some of the PHP code to the screen


a) what is the name of the script
b) where is it stored (full path)
c) how do you "open" the file in FF (i.e. what do you enter into FF in order to open it)
Nobbie
 
Posts: 8769
Joined: 09. March 2008 13:04

Re: PHP Displays in Plain Text

Postby rquaid.pro » 01. September 2010 18:16

Nobbie wrote:a) what is the name of the script
b) where is it stored (full path)


c:\xampp\htdocs\kcsunshine\characters.php

Nobbie wrote:c) how do you "open" the file in FF (i.e. what do you enter into FF in order to open it)


I tried multiple ways. The file is actually part of a larger site that uses frames. I loaded the characters.php page up by itself at first and that's when my problem first happened. I thought it might be related to the frames somehow so I tried loading it up through the actual site like I had been before when it was working but it still did the same thing. FF is set as the default browser on the server, so I just double-clicked the characters.php file and the index.htm file to open them.

As another note, I wrote a very basic test page (c:\xampp\htdocs\kcsunshine\test.php) and I'm having what I think is the same problem. Obviously there's no real PHP code to dump to the screen, but I can tell that there's a problem because if I "View Source" I can still see the PHP tag.

Code: Select all
<?php

?>
<html><head></head>
<body><p>This is a test.</p></body>
</html>


Thanks again for the help,
-Quaid
rquaid.pro
 
Posts: 4
Joined: 01. September 2010 09:04

Re: PHP Displays in Plain Text

Postby Nobbie » 01. September 2010 20:59

rquaid.pro wrote:FF is set as the default browser on the server, so I just double-clicked the characters.php file and the index.htm file to open them.


Thats what i thought. You CANNOT simply double click a PHP Script. That does not work.

You have installed a webserver (Apache) and ONLY IF Apache delivers a PHP script, it is interpreted by an PHP Interpreter. Simply double clicking does neither involve Apache nor PHP. Your browser dont know how to start PHP. It simply opens the file - nothing else. You MUST enter a valid URL into your browser, and an URL for a HTTP Request always starts with "http://" followed by domain name (what is "localhost" on your PC) and followed by file name (optional folders between).

I.e. if you have stored a file to c:/xampp/htdocs/kcsunshine/characters.php (forward slash works as well as backslash) and c:/xampp/htdocs is your DocumentRoot (Apache Configuration), you MUST enter the following URL into your browser in order to "request" that file from your local webserver:

http://localhost/kcsunshine/characters.php (you may simply click on this link - if your Apache is running)

Also start your HTML files via http://localhost/... - never use double click.
Nobbie
 
Posts: 8769
Joined: 09. March 2008 13:04

Re: PHP Displays in Plain Text

Postby rquaid.pro » 01. September 2010 21:59

I knew it would be something simple that I was overlooking. That seems to have fixed the problem. Thanks for the help, Nobbie.

-Quaid
rquaid.pro
 
Posts: 4
Joined: 01. September 2010 09:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 81 guests