PHP script code is displayed instead of executed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kekec
Forum Newbie
Posts: 6
Joined: Tue Nov 08, 2005 2:42 am
Location: Slovenia

PHP script code is displayed instead of executed

Post by kekec »

Hello everybody,

I am a newbie in php and this is my first post to the php community.
I installed Apache 1.3 and php 4 (I got both of them on a CD together with a book about MySQL and php) on Win XP and started to learn php.
The installation of php has been tested with the command http://localhost/info.php and the known php configuration text was displayed.
This means that a php installation was successful. Whenever I start a php script directly in form http://localhost/xxx.php the script works fine.

The problem appears when I want to use a form together with a php script. I prepared a simple form with one text field and submit button:

<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p><input type="submit" /></p>
</form>

The action.php is:

Hello <?php echo $_POST['name']; ?>.

If I submit the name (for example "kekec", then the browser shoes the above mentioned source code of the php script instead of "Hello kekec".

Any idea or advice is very appreciated.

kekec
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

did you name the file .php? is php actually installed on your server? is it configured to process .php files or did someone change it to something loopy?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Well, he said it worked...

That is a bit loopy. What happens when you call action.php directly (without a POST)?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I will bet it'd show the code..

I'm going to guess your book told you to install it via the CGI handler, which then limits PHP execution to a particular handling directory and is slower than running PHP as a module. If so, install php as a module instead (following the instructions found in the zip, at least, download)
kekec
Forum Newbie
Posts: 6
Joined: Tue Nov 08, 2005 2:42 am
Location: Slovenia

Post by kekec »

feyd, you will loose :D.
Running action.php alone shows

Hello .

instead of "Hello kekec ." which would be correct, or a source code.

I copied the php directory from the CD, then modified php.ini (doc_root, extension_dir, display_errors, enabled php_gd.dll), copied php4ts.dll into system32 directory.

Finally I added the following lines to the httpd.conf:

LoadModule php4_module c:/web/php/sapi/php4apache.dll
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php4

As far as I know (well, I am new here) this a standard php installation. Perhaps something is still missing.

kekec
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

What happens when you try to access action.php?var=value
kekec
Forum Newbie
Posts: 6
Joined: Tue Nov 08, 2005 2:42 am
Location: Slovenia

Post by kekec »

@Ambush Commander

It is still the same - only Hello .

i.e. without the name.

kekec
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Code: Select all

<form action="action.php" method="post">
<input type="submit" />
</form>
Try that. And BTW, make sure you're still on localhost after the form submits.

To be completely honest, I have no clue why POST requests are getting selectively dropped. If you're a little impatient, you can uninstall and then install straight from the horses mouth...
kekec
Forum Newbie
Posts: 6
Joined: Tue Nov 08, 2005 2:42 am
Location: Slovenia

Post by kekec »

no changes - still the same.

kekec
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You mean it shows the source?
kekec
Forum Newbie
Posts: 6
Joined: Tue Nov 08, 2005 2:42 am
Location: Slovenia

Post by kekec »

sorry, it's getting late here.
It shows the source code

kekec
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Are you sure you actually have PHP installed at all?

If you're having trouble with it, get XAMPP. It's a complete package that should work out of the box.
kekec
Forum Newbie
Posts: 6
Joined: Tue Nov 08, 2005 2:42 am
Location: Slovenia

Post by kekec »

I installed php 4.4.1 from scratch, RTFM and now it works.
Thanks to all of you who spent your time with a problem of a newbie.

till the next time :oops:

kekec
Post Reply