PHP shows as source code.

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

PHP shows as source code.

Postby Ginn » 17. January 2011 14:09

Good day and thank you in advance,
ofc i have a prob, thats why im here.

Here it goes:

I have a page including a form. It uses post to get the data over to the next page.
The next page is a post receiver, where it echo's the received data before submitting it to the DB.
When opening the receiving page via locahost/dir/page.html it shows the echo.
But when redirected trough the action from the HTML form, the page shows as the source code.

(<form name="Registreren" id="Registratie_form" method="post" action="testPOST.html" onsubmit="return Validate();">)

I looked trough the forum, but coulndt find anything that could help me. Perhaps im just too noobish..

Perhaps this is the problem:

by Altrea » 04. April 2010 07:47:
There is NO reason to put php code into html files. Thats just sloppy programming.


Sloppy programming. But the pages have to fit the website's style.. So how could I do it then?


Tried using a .php file, still shows the source.


I call the page with testPOST.html wich gives me C/dir/xamp/root/dir/page
Calling the initial page with localhost..



Im noobish with PHP, but can figure most things out. So Jargon is do-able.


EDIT: Restarted PC and now it wont show the source, it shows nothing at all. Some files can even be found? Xampp put 2 files in HTdocs, index.html and index.php. INdex.php is worth a nto found error 404.. And html does show... With C/dir/dir/dir/page its found, but again as source.
There are no other progs installed so its prob not a conflict..






Perhaps Xampp inst configed correctly or ..?

Kindr egards and thank you in advance.


Ginn
Last edited by Ginn on 17. January 2011 14:52, edited 1 time in total.
Ginn
 
Posts: 2
Joined: 17. January 2011 13:53

Re: PHP shows as source code.

Postby stevek » 17. January 2011 14:41

When using php and html in one page I found that is works better is you use the *.php extension on your pages instead of html.

This does not mean that you do not have to declared your language (<?php code goes here; ?> but I found that it mixes better.

You could just post the code for you output form here (if that is not against forum rules).
stevek
 
Posts: 4
Joined: 17. January 2011 09:34

Re: PHP shows as source code.

Postby Altrea » 17. January 2011 16:16

You can't just open the php files in the browser (doubleclick on the file won't work too)!
You have to request the files with the HTTP protocol ( http://localhost/subdir/filename.php )
and your files had to be saved into your xampp htdocs folder.

e.g.:
You have a file c:\xampp\htdocs\projectxy\file.php
then you can request it through the URL http://localhost/projectxy/file.php
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8293
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: PHP shows as source code.

Postby Ginn » 17. January 2011 22:20

I know, that doesnt work either. All i get is a blank page. No simple echo or anything else..

Btw, hope that you dont mind that I used your name in the post.


Kind regards.

Ginn
Ginn
 
Posts: 2
Joined: 17. January 2011 13:53

Re: PHP shows as source code.

Postby Altrea » 18. January 2011 05:52

Ginn wrote:Btw, hope that you dont mind that I used your name in the post.

I remembered that i posted this sentence in another post, so you just quoted me to get an answer on a question.

Ginn wrote:
Altrea wrote:There is NO reason to put php code into html files. Thats just sloppy programming.

Sloppy programming. But the pages have to fit the website's style.. So how could I do it then?

Very easy! You can use HTML and CSS in your PHP Pages too. You can style them as every normal HTML page.

The reason why Pages with PHP code in it must have a .php extension is that your Apache is by default configured to send .php Pages through the php parser, html pages just bypass the Apache and are send directly to the browser. The PHP-Parser don't get .html files so php code will not be executed.

Okay. To solve your Problem, we have to start at the very beginning.
- Check if your Apache is running (open your XAMPP control panel. There had to be a green running label next to the Apache start/stop Button)
- If your Apache is running, check if you can start your browser and request http://localhost/ . You should see the XAMPP backend screen (or a language choice).
- If you can see the XAMPP backend, try the phpinfo() link in your XAMPP Backend. This is just a test to see, if Apache and PHP are working correct.

If these checks are successful, the reason for your problem is either your script(s) or the way you request your scripts.
So, you should post your sourcecodes of the two scripts (form and receiver). Please use the "Code BB-Code" if you post your code here.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8293
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 69 guests