PHP not executing with XAMPP (Windows) - php

(Edited for clarification) I am trying to execute some PHP code in a file called "index.php" using the Apache web server in XAMPP. The file is located at C:\xampp\htdocs\index.php.txt (not sure how to get rid of the .txt suffix). I am accessing the file by typing "http://localhost/index.php.txt" into my browser. The code is:
<!DOCTYPE html>
<html>
<body>
<?php echo "It works!"; ?>
</body>
</html>
When I select the file in the Apache server only the code itself shows up. I've been searching around for a while and I can't seem to find the issue. Thanks in advance.

Your PHP code are not executing because the server interpret the file as text file, hence why the codes are not executing. This is due to your file name, which have .txt extension.
not sure how to get rid of the .txt suffix
Use any code editor like Notepad++ to save the file as PHP file, hence getting rid of the .txt extension.
Or for normal Windows Notepad, just select save as "all file", and the file name make sure only "index.php".

Related

php file getting recognized but not giving input

I have a html and php in "C:\wamp64\www\module", html file is able to access php file but the php file is not outputting anything. It's blank, it's not even printing the code like it usually happens.
Following is the php code:
<html>
<body>
<?php
phpinfo();
?>
</body>
</html>
When I execute "file:///C:/wamp64/www/module/html.html" this file, "file:///C:/wamp64/www/module/phpworking.php" this is the address I get and the page is totally blank.
WHAT IS THE PROBLEM???
If you have already enabled your wamp server, you need to access your files through your browser via http://localhost/name_of_your_file.php

PHP being commented out when uploaded to server (Ipage)

I am new to PHP and am trying to run my first script. I read that to to run php on your pc, you have run a server on it which I didn't feel like doing.
So instead I am trying to run it on a server hosted by Ipage.com
The program is just a basic html file with a set of full tags
I have tried linking windows explorer using ftp, using the "upload" button on the website and directly editing the file using the editer on the site. When ever I add the php tags and save or upload the file, when I go to view it on the ipage file manager, they are commented out
This is what happens to the file when I upload it
<!DOCTYPE html>
<html>
<title>Striations</title>
<head>
<link href="css/LandingPageStyle.css" type="text/css" rel="stylesheet">
</head>
<body>
<!--?php echo "HELLO"; ?--> //originally <?php echo "HELLO"; ?>
<h2>Our site is currently under construction, please check back later!</h2>
<img src="media/construction man.png"></img>
</body>
</html>
I'm totally new to php and hosting and stuff and I could be missing some important step regarding how to run php
I'd appreciate and explanation of how php is transferred into html before being sent to the browser
EDIT:: I know as a fact that ipage supports php, they had mentioned something about changing my root file directory, but even when I moved my files to where they said, it did the same thing
Is there something else I should be doing to enable php?
It is an html file with php tags... I'm supposed to save it as .html, right?
If you saved this as index.html then the PHP parser won't run it by default. Either name it index.php or (if you can) use htaccess to parse HTML files as PHP

the php codes don't run but my html code run correctly

i want to start php programming.
i use Dreamweaver IDE and WAMP Server.
when i run codes, the php codes, doesn't execute.
when my html code, run correctly.
for example when i use the following code:
<html>
<head>Hello</head>
<body>
<h1>Hello</h1>
<?php
echo("echoString");
?>
</body>
</html>
the "Hello" Message shows on the screen but "echoString" doesn't show.
my WAMP Server Installed and worked correctly.
i see the html output in my browser.
thanks
use the file with .php extension instead of .html like yourfilename.php and place the file in www folder , run it by going to
localhost/youfilename.php

PHP code doesn't show while using Dreamweaver

I create a new HTML file for my project using Dreamweaver and i added a simple php code:
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
so far nothing is appearing while i open the file with google chrome and IE, any thoughts?
PHP has to be executed on the server. Upload it to a web server that supports PHP, or install your own web server locally such as WAMP. You then need to access the file with a URL rather than just opening it. A local URL will look like http://localhost/ or http://127.0.0.1/.
Your file also needs to have the extension .php if it contains PHP code. If you really want to use PHP inside a .html file, your web server will need to be set up specially to handle this.
PHP requires a webserver and an interpreter. Browsers cannot handle PHP on its own.
Look at XAMPP
A good idea to check if your php file is working properly is to load phpinfo function.
This function will show details about your PHP installation:
<?php
phpinfo();
?>
If what you see on the screen is this php code with the entire opening and closing tags (), then you are not running the page with PHP.

Why is echo printing past the quotations?

<!DOCTYPE HTML>
<html>
<body>
<?php
//printing
echo "<p>Hello, World</p>";
?>
</body>
</html>
This is suppose to be a basic hello world example but when I run it in the browser I get an extra "; ?>
Hello, World
"; ?>
Why is that?
EDIT: Yes the file extension is php
EDIT2: I created the file with Notepadd++. I ran the file by right clicking the file and open with chrome.
EDIT3: Okay so what I gathered is that I can't just run the file locally. I will try through a web server. Thank you for the responses so far!
I believe your problem is that you do not have a local server such as xampp.
I would suggest downloading xampp and then follow the instructions for running a php file.
Make sure you have .php as the file extension
You are probably not running your file through your web server, but you are opening it locally.
Make sure your url is something like http://localhost/myFile.php. And not c:\documents and settings\myName\Desktop\myFile.php.
"I created the file with Notepadd++. I ran the file by right clicking
the file and open with chrome."
You are saying your problem. PHP files are not like HTML files. They must be compiled before served.
For example:
<html><body><?php echo date("Y"); ?><body><html>
will be expected to show the system year. If you try to open it browser does not recognize PHP scripts and treats that function as a text and you see
echo date("Y"); ?>
Why don't you see <?php ? Because after <character, the browser thinks that there is an HTML tag coming.
If you run that PHP file correctly and then look at the source HTML you will see
<html><body>2014<body><html>
You must move the file to web server directory like c:\xampp\www or to c:\wamp\www.
Then run apache server.
After that open a browser window and type localhost/yourfile.php:80
80 could vary in according to your settings (Take a look at httpd.conf file).

Categories