PHP not working in Firefox on ubuntu 20.04 - php

In firefox I repeatedly tried to get PHP working, but no luck
My code is as follows:
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
I used PHP format, but it wanted to save the script again.
XML threw a boatload of errors.
HTML did not show the PHP

Related

simple php code not been executed

I am trying to create a simple php page which contain only an echo, if I saved the page as ".html" it will be opened on google chrome but nothing is executed, if ".php" the page never open. any help? PS: I am new on programing
<html>
<head>
<title> test</title>
</head>
<body>
echo "hello World";
</body>
</html>
You have to write your PHP code between PHP open <?php and close ?> tags.
Try this :
<html>
<head>
<title> test</title>
</head>
<body>
<?php echo "hello World"; ?>
</body>
</html>
Php file don't run .html format and without server . Please read and understand what is php and how it is work ?. follow below link or find youtube tutorial for more visual understanding .
https://www.w3schools.com/php/default.asp
http://php.net/manual/en/
Maybe you try this :
<html>
<head>
<title> test</title>
</head>
<body>
<?php echo "hello World"; ?>
</body>
</html>
Save file as .php format and run through a localhost server that you prefer . if you don't know what is server is
follow link :
https://www.w3schools.com/php/php_install.asp
PHP server on local machine?
Download XAMPP, change your code to
<html>
<head>
<title> test</title>
</head>
<body>
<?php echo "hello World"; ?>
</body>
</html>
Locate the folder C:/xampp/htdocs, and create the file index.php containing your code, now type "localhost" in your web browser and you're done

I've moved a site to GCE w/ LAMP and my PHP is outputting extra characters

My code looks like this:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
and outputs this:
Hello World
'; ?>
What are those extra characters doing there?
Thanks!
You can't end a file in .html and expect your web server to parse it as PHP.
In that case it's sent directly to the browser without anything being parsed or executed as PHP.
Instead, save it as index.php for example, then view it in your browser. If you have PHP installed then you should get the output you expect.
Seems like you have saved your file with .html extension instead of .php.

Running php script from HTML file WAMP

So I have been following this tutorial here
I have installed WAMP and the server is up and running just fine. (As the green light in the taskbar indicates).
In the www folder I have the following 2 files:
<!DOCTYPE html>
<html>
<head>
<title>First Form</title>
</head>
<body>
<form action="postForm.php" method="post">
<TextArea
name="microBlog" id="microBlog" cols="30" rows=“10">
</TextArea>
<input type="submit">
</form>
</body>
</html>
and
<!DOCTYPE html>
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$microBlog = $_POST['microBlog'];
echo $microBlog;
?>
</body>
</html>
However, when I run the html file and input "hello" into the field, clicking the submit button returns a blank screen.
Here is the html screen on open:
and on clicking submit the following is in the address bar:
file:///C:/wamp/www/postForm.php
Any ideas why the blank screen?
Does the PHP (postForm) file require HTML tags or can I get rid of them?
Open the file via http://localhost/...
The reason for the blank screen is:
You can open a html-file with the explorer and it will work fine because it will be rendered by the default-web-browser. you need a parser for php-scripts. The Webserver will use this parser if you add the extension .php but if you open the file in the Explorer you don't use the Webserver (in your case apache). If you want to open the file in the explorer set the action-attribute to action="http://localhost/postForm.php" and it will work.
You should use
action="http://localhost/postForm.php"
instead of
action="postForm.php"
hope this help :)

localhost/test.php returns nothing

I am following a tutorial "PHP & MySQL for dummies" to build a web application. I created a simple test.php file in web space (/var/www/html). The problem is that when I type localhost/test.php in the browser address window, it returns me an empty page. I tried localhost/php.info and it worked well but I could not find why test.php does not work.
This is the test.php code:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<p>This is an HTML line
<p>
<?php
echo “This is a PHP line”;
phpinfo();
?>
</body></html>
I do appreciate any information.
Thanks.
You said that you put your script in /var/www/html
So the link might be
localhost/html/test.php
Also check the error log file for PHP error.
# cat /var/log/apache2/error.log
EDIT: Change your quote, ” are for Word document and not programming ;-)
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<p>This is an HTML line</p>
<?php
echo "This is a PHP line";
phpinfo();
?>
</body>
</html>
I have tried with this..just type the word localhost followed with name of the work eg.. localhost/test.php in the navigate bar on your browser then click enter

php web page not loading

I am not an expert but I am no noob at PHP, yet for whatever reason I am stomped as to why my document will not load. Here is my code.
<?php include 'header.php'; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<body>
<p>Hello everyone</p>
</body>
</html>
When I pull out the PHP portion the HTML loads fine. Here is the code in my header.php file.
<?php
<href="index.php">Home</a>
?>
I have tried this on two different hosts, both of which are hosting other PHP websites and still getting issues. I have also validated it with W3Schools and another online PHP validator. Both didn't find any errors. Any help would be greatly appreciated.
Enable errors to see errors, this way:
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);
This code is a PHP error:
<?php
<href="index.php">Home</a>
?>
Try change to:
<?php
echo '<href="index.php">Home</a>';
?>
This:
<?php
<href="index.php">Home</a>
?>
Is no valid PHP. This would, however work:
Home
Inside of the PHP-tags you can only use PHP - no HTML. Also, <href> is no HTML tag.
Look at this question How to get useful error messages in PHP? to find out, how to enable error messages in PHP.

Categories