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
Related
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
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
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.
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 :)
When I create file index.php in directory /public/ my source code
<html>
<meta name="ROBOTS" content="NOARCHIVE">
<head><NOFOLLOW><noindex>
<?php echo '123' ?>
</NOINDEX></NOFOLLOW>
</head>
<body>
</body>
</html>
from browser looks like
<html>
<meta name="ROBOTS" content="NOARCHIVE">
<head><NOFOLLOW><noindex>
123
</NOINDEX></NOFOLLOW>
</head>
<body>
</body>
</html>
but if I create folder (no matter where) and place file index.php into it when source code become
<html>
<meta name="ROBOTS" content="NOARCHIVE">
<head><NOFOLLOW><noindex>
if I make some correction in this file, source code stay the same, not changed in browser view.
Why I cant create and run php code where I want, except /public/ folder?
Is that the exact code you are using in both index.php files?
If so, they should both fail as there is a syntax error. You are missing the ; at the end of the php code.
You posted: <?php echo '123' ?>
Should be : <?php echo '123'; ?>
If that´s not the case, you could add the following to the top of index.php to make sure the errors are showing on the page:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
If any error appear after that, please post them back here.