The simplest code not working (built in server) [duplicate] - php

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 4 years ago.
php7.2
Could you help me understand why my code is not working?
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
Please, have a look at the attached image.
I run the built in server.

On a hunch I will take a guess that you are missing the file extension of .php

Related

Failing to pass variables via URL to php page [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
Im trying to send 2 variables to my php page via a link, i can't figure out what im doing wrong. The outcome is not right. Im expecting just the display of values and instead the whole php code displays.
Thanks for helping in advance, below is my html, php and result.
My html page is named "index.html" and my php "default.php"
HTML:
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Information sänd via adressfältet och länkar</title>
<meta charset="UTF-8">
</head>
<body>
Link
</body>
</html>
php:
<?php
header("Content-Type: text/plain");
echo $_GET["name"];
echo $_GET["gender"];
?>
Result:
<?php
header("Content-Type: text/plain");
echo $_GET["name"];
echo $_GET["gender"];
?>
There are a couple of factors affecting such
first one confirm that your php module is properly configured to Apache and it reads the .php extension
two that your file is actually saved as .php if you are using a text-editor like notepad which appends the .txt file format at the end, unless you select file type as all files
I found the problem thnx to this thread: PHP code is not being executed, instead code shows on the page
The problem was:
Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

My php script isn't visible in the browser [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
I just started PHP I got my XAMMP server up and running and now I made my first html test page and added one line of PHP script but it isn't showing in my browser.
<!DOCTYPE html>
<html lang="nl">
<head>
<title>Mijn php-script</title>
</head>
<body>
<?php
phpinfo();
?>
</body>
</html>
It does however shows the title I gave it, can anybody tell me why the rest isn't showing? it should show the info version page of my PHP.
You need to save your file as .PHP and not as .HTML in order to be able to run this. Also, you need to fix the HTML closing tag in the end, as you are closing the HEAD again.

PHP seems to run the first line then the rest displays in browser [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 6 years ago.
So I am learning PHP from a book and I understand it is done server side. I installed wampserver and it's running. When I open my php file, it'll run the first line but the rest just displays in the browser. Here's the code:
<!DOCTYPE html>
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo "<p>Order processed at ";
echo date('H:i, jS F Y');
echo "</p>";
?>
</body>
</html>
Here's what displays: Screen Shot
It displays the first 'echo' statement it seems. But the rest... I haven't changed any settings on the wampserver program, I just installed it and made sure all services were started up. Is there something else I need to do?
I'm using Windows 10.
I think PHP doesn't run at all.
Look in your source code in your browser, if you can see <?php your PHP doesn't work.
Create a file "info.php" and write the code: <?php phpinfo(); ?> to test your PHP.

Echo is not working with HTML inside of php but working with php [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 6 years ago.
This is working when I open it with ubuntu terminal
First.php
<?php
echo "My first PHP script!";
?>
But I have made one HTML with Same confiuration
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
When I open it in browser it shows empty
Any help will be appreciated
You need a php extension on any webserver running that parses the script, you cant just input php to an html file and open this one. PHP is a serverside language not a clientside
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
Save this file as for example mytest.php and run on the browser
output is :: My first PHP script
Try it OR you can run it from terminal as well
Always save file with php extension if it has php code for Cor PHP. You can put HTML/javascript/css code inside a filename.php file but outside tags, that will work fine.

simple PHP echo not working [duplicate]

This question already has answers here:
Simple PHP echo code not working
(9 answers)
Closed 9 years ago.
I am trying to learn basics of php.So I tried following example as in http://www.w3schools.com/
<!DOCTYPE html>
<html>
<body>
<h1>A Header</h1>
<?php
echo "My first PHP script!";
?>
</body>
</html>
This code was working two days ago. But now PHP part doesn't work.I have read this thread,but It is not that problem. Please help. Thank you.
Make sure that your web-server can execute php-scripts. Go through this: http://php.net/manual/en/install.php
I recommend you start learning PHP using this website http://www.developphp.com/list_php.php#Getting_Started_with_PHP_Programming it has everything you need to get you started, tutorials are nice and easy to follow :)
Check the Installation section and then maybe have a look at this one http://www.developphp.com/view_lesson.php?v=194 to solve your problem.
Hope it helps!- Good Luck!

Categories