Jump to content



Photo

Script 1.5 showing PHP code


  • Please log in to reply
8 replies to this topic

#1 bear712

bear712

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 24 January 2012 - 7:06 PM

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.
  • 0

#2 Josee

Josee

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts

Posted 25 January 2012 - 3:56 AM

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,
  • 0

#3 bear712

bear712

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 25 January 2012 - 11:31 AM

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!
  • 0

#4 HartleySan

HartleySan

    Advanced Member

  • Members
  • PipPipPip
  • 2,838 posts
  • LocationColumbus, OH USA

Posted 27 January 2012 - 1:48 AM

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.
  • 0

#5 Paul Swanson

Paul Swanson

    Excellent Advisor

  • Members
  • PipPipPip
  • 163 posts
  • LocationPortland, OR, USA

Posted 27 January 2012 - 1:11 PM

Are you sure PHP is running? Try a script with just:
<?php
phpinfo();
?>
Do you get the PHP Information page?
  • 1

#6 bear712

bear712

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 30 January 2012 - 10:12 AM

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
  • 0

#7 bear712

bear712

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 30 January 2012 - 10:21 AM

Okay, i feel pretty SLOW for this but i just ran my htm doc written as localhost/form.htm and then tested it out and everything is working fine. Sorry for the unnecessary post.
  • 0

#8 Paul Swanson

Paul Swanson

    Excellent Advisor

  • Members
  • PipPipPip
  • 163 posts
  • LocationPortland, OR, USA

Posted 30 January 2012 - 12:42 PM

For testing PHP, you must use localhost as the address. This is because PHP is a running via the webserver (localhost) and if you open it as a file you are bypassing the webserver, so your browser just sees normal text rather than the parsed PHP code.
  • 0

#9 bear712

bear712

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 30 January 2012 - 8:27 PM

Thank you for that clarification.
  • 0