php script not rendering - php

so i worked on a php project on my localhost and every thing was ok but now, every php file im trying to open just downloads itself (Chrome) or asks if i want to download it (Firefox). i tried to go back to as basic as possible and came out with this index.php file :
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
but the only way i can open it without downloading itself is if im changing it to .html file and than i just don't see the hello world. i already re-installed xampp. i can go to phpmyadmin on my local (if it helps) and thats unfortunately all te useful information i can come up with...any help please?

Make sure your httpd.conf has properly configured php module. And, you have enabled support for php files.

Related

Display html page in php file

I know a bit of HTML but I'm trying to learn PHP right now. Say I have a simple .php file like this:
<?php
?>
<!DOCTYPE html>
<html>
<body>
<h1>Title</h1>
</body>
</html>
If I'm on a mac, how do I get my browser to display the webpage represented by the HTML in this file? When I try open the PHP file it shows the actual HTML code, not the header. Apologies for the noobie question, I'm going through a PHP tutorial right now and the instructor did not elaborate on how to actually display the HTML inside the .php file so I'm a bit confused. He's running it through his localhost it seems.
So the deal with php, is that your browser can't run php code, that is done by the server. You'll need to get a local server to run it then. Since you're on a mac this should be alright:
https://www.mamp.info/en/
Once you've got that running, you'll need to put your php file into the 'htdocs' folder of the MAMP stack install. After that you can access it by navigating to localhost/filename.php
You need a local host to run your php script like MAMP for your mac. simply you can use free web hosting service from different online free host web server like Hostinger
You can't run a php file directly on your web browser that your are using.You need to have a local server host in-order to run your php file. Try downloading an using wamp server,Apache etc.
http://www.wampserver.com/

How to get Embedded PHP working in HTML?

I am a beginner in PHP and I am trying to embed PHP in HTML as that is how I am going to need it in my project. This one is a very simple code saved as Trial.html
<html>
<head>
<title>Trial Page</title>
</head>
<body>
Hello, today is <?php echo "a great day!"; ?>.
</body>
</html>
When I load this page from server (I am running Apache Tomcat 7 locally), Only the HTML part is getting displayed and the PHP part is not. What am I missing? Do I need to include anything else or am I taking a completely wrong approach for this?
Rename "Trial.html" to "Trial.php" this is essential when you try to run php code.
You should save your file as .php and run it on a server with php installed on it.
check XAMP to install a local server
EDIT
Just saw that you're running Tomcat, just make sure php is installed, that your server is running, you're running your file from the server And your file is save as .php
You change file name from trial.html to trial.php

Want to learn how to use php to save data in forms. How come this doesn't work in a html file?

I'm a newbie please bear with me. I just finished learning how to create forms in html. Now, I want to learn how to save and display the data using php. While following along the php exercises in w3, I tried running this file but it didn't work when saved as a .html file. Could someone explain what I'm doing wrong and why the code text won't display? Thanks.
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
Your server is not setup to parse PHP in files with a .html extension. Add an .htaccess file to your web root with the following lines in it -
# allows HTML files to be interpretted as PHP files
AddType application/x-httpd-php .html
You should save it with a .php extension. I assume you're working locally and you would need to install PHP on your machine. The best way to install it locally is by using XAMPP or WAMP to emulate a server. I prefer using XAMPP https://www.apachefriends.org/index.html. Install it start the apache service, put this file in your htdocs folder i.e. 'root' and navigate to 127.0.0.1 from the browser. This is a start, even if you put it on an "actual" server it'll work fine.
First off, you need to change your file extension from .html to .php
Are you running a web server? If not, you need to either be running a server like MAMP
just done you a quick form here
Copy and paste it to where ever you run you script,make sure it has a php extension, and see if it gives you the same result as it does in the link. If not then your configuration is wrong. If you have xampp then make sure it is in the HTDOCS directory

My PHP file gives code instead of output

I've already tried the advice given on this page, by opening my .php page with Chrome, Mozilla, and IE (instead of dragging it to them), my EasyPHP is started (along with the other services I just installed with it), my files are located in C:\inetpub\wwwroot (on Vista), and so far, no PHP is being outputted. It either shows up as code on the page, or it doesn't work at all (includes don't work, for example). I tried configuring the DirectoryRoot in the httpd.config file (I commented out the original first, instead of deleting it), so it would point to the wwwroot directory, but that didn't work either. I am very new to EasyPHP and it's been a few years since I really dealt with regular PHP, Apache, and MySQL, so I'm grasping at straws here.
The code in my .htm file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>
<title>MySite</title><link href="MySite.css" rel="stylesheet" type="text/css"></head>
<body>
<?php
include("topbar.php");
?>
<div id="content">
<h2>Content Goes Here</h2>
</div>
</body>
</html>
The code in my topbar.php file:
<?php
echo '<div id="container"><div id="header">';
echo '<h1>This is the header.</h1><p class="description">';
echo 'Usually some sort of tagline or description is placed here.</p></div>';
?>
I don't know. I've been searching all over the PHP main site, as well as a few random pages that came up when I used my search engine... I've gone through the EasyPHP FAQ page, and I haven't yet found an answer the would point me in the right direction. Other than attempting to edit the httpd.config file, I haven't gone through any other files created by EasyPHP, mainly because I wouldn't know which ones to try editing, nor which lines, or with what. I just installed EasyPHP last night. I'm glad for any assistance anyone can provide in plain English (please, no one try to show off how cool you are with all your fancy technobabble that I'd have to get out a tech dictionary for, or lengthy examples that would be hard for a newb to read, thanks).
Web server will not process PHP code written in file extension other than .php. Try changing file extension to .php instead of .html.
You can use HTML tags within .php file.

PHP not rendering in HTML

I am using Windows 7 with IIS 7.
I am trying to get started with PHP. I have performed the following:
Installed PHP using the web platform installer
Verified that PHP is installed by using 'Check phpinfo()' on the PHP manager within the root folder of my website (all on my local machine)
When I test to see if PHP is working with a simple HTML page as follows:
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
Chrome does not render anything. I am expecting to see the text.
Can anyone advise me how to proceed?
Thanks
If this problem ocurrs check:
Does the file have extension .php?
Does the path is correct on the server?
Its is important to remember that I am assuming that you have a server with php suport activated. On the server, the default extension to PHP files is .php, but you can check with the administrator to garantee.
You can also check if the error log is enable. When it is disabled, and the code has a syntax error, nothing is showed on the screen. You can read more here: https://stackoverflow.com/a/5438125/1735789

Categories