Jump to content
Larry Ullman's Book Forums

Script 1.5 showing PHP code


Recommended Posts

Hello all,

 

I apologize in advance if this is not the correct topic for this question but i did not want to start up a new one.

 

I am having some issues with the scripts starting at script 1.5.

 

Up until this point everything was working fine. I have downloaded XAMPP, PHP Designer (as my IDE). Like i stated earlier whenever i try to run script 1.5 i get the output that looks like this:

 

You are running the file:

$file.

 

\n"; ?>

 

This is my code (i left out the other two vars in the script as a test):

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Predefined Variables</title>
</head>
<body>
<?php #Script 1.5 - predefined.php
$file = $_SERVER['SCRIPT_FILENAME'];

//print the name of this script
echo "<p>You are running the
file:<br /><b>$file</b>.</p>\n";
?>
</body>
</html>

 

 

Any ideas to what could possibly going wrong?

 

Thanks to anyone who can offer some advice.

Link to comment
Share on other sites

I think your mistake is that you are just opening the file in your browser (if that's the case, the address begins with file://) instead of running it through your local server (in that case, the address begins with http://, and probably looks like http://localhost:8888/directory/predefined.php). You need to run it through your XAMPP server so that the server can interpret the PHP code. See Larry's explanations on page 4.

 

I hope this helps,

Link to comment
Share on other sites

Thanks Josee for the quick reply, i was doing what you suggested and kept trying with no different result. I downloaded the scripts and just copied the code and it worked just fine. Not sure what the problem was. Thanks anyway!

Link to comment
Share on other sites

The problem seems to be with \n, but I honestly don't know why.

 

Try to output a simpler string for the time being. For example:

 

echo "I went to the store to buy:\n4 apples";

 

See what kind of output you get, and see if you can figure out things from there. There may also be some option that you're unaware of in your IDE that affects either the behavior of double quotes or the \n symbol.

Link to comment
Share on other sites

Hi Paul I do get the php information page. Apparently I am back to having the same problem again but this time with script 2.1 and 2.2. I get the form to work fine just by opening it up in the browser (chrome) and the address is written as:

 

file:///C:/xampp/htdocs/form.htm

 

and then when i click submit it displays as:

 

Thank you $name for the following comments:

$comments

We will reply to you at $email.

\n"; ?>

 

 

With the address as:

 

file:///C:/xampp/htdocs/handle_form.php

 

I know php files need to be run through the server (where the address begins with http://), but I do not know how to do that or if it should just happen automatically. This issue has been holding me up for a few days and preventing me from continuing. Any help would do. Thanks

Link to comment
Share on other sites

 Share

×
×
  • Create New...