Strange behaviour of php using wamp - php

I have been using wamp server do build small websites with php for a long time.. but this morning something strange just happend :
here is my home.html file :
<html>
<head>
<title>Test PHP</title>
</head>
<body>
<?php echo '<p>Hello world</p>'; ?>
</body>
</html>
and here is what I get when I display the page :
Hello world
'; ?>
And when I display the source code, here is what I get :
<html>
<head>
<title>Test PHP</title>
</head>
<body>
<?php echo '<p>Hello world</p>'; ?>
</body>
</html>
It seems to be a very stupid problem where the php code is not interpreted by the server.. Any suggestion ?

You saved the filename as .html
Use .php instead of .html it will interrupt.

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

php isn't processed correctly

Thanks in advance for your help, I am pretty sure you can solve my problem.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>
<?php
echo '<p>hello world</p>';
?>
</body>
</html>
Previous Code example does display
hello world
'; ?>
instead of the expected
hello world
This was run local with xampp V3.2.2 on a win10 OS and Chrome browser.
I hope I'm not the fiftieth person to ask this just because I couldn't google it correctly.
Thanks for your help.

Php include add title tag

Okay people, its something very common the only thing is that I have no idea how to deal with it. i have a file "login.php" the codes within the file are
<div><textarea>Eneter your description</textarea></div>
I have a second file name "index.php" and the html inside it are
<html>
<head>
<title>SMO</title>
</head>
<body>
<?php include_once("login.php"); ?>
</body>
</html>
The problem i am facing is that, when php include login.php it also add a <title></title> tag hence i am left with two title tags.
Please help me sort it out. I know its a kid things. but just could not figure out how to solve this.
login.php
<html>
<head>
<title>SMO</title>
</head>
<body>
<div><textarea>Eneter your description</textarea></div>
</body>
</html>
index.php
<html>
<head>
<title>SMO</title>
</head>
<body>
<?php include_once("login.php"); ?>
</body>
</html>
Is this your code?
If yes, you don't have to add the <title> in your login.php page.Remove <title> and it'll work fine.
If no, please include your code in your question.
So your login.php page should be like
<div><textarea>Eneter your description</textarea></div>

PHP - HTML Script being placed within 'body' tags

I have been developing a page on my webserver (using nano on the actual server) and I have been experimenting with the INCLUDE statement as an attempt to hide database details from the end user. However, my html is being placed within BODY tags according to Firefox's Inspector.
Here is the result in firefox and below that is the code for my page.
<?php
include "/database.php";
?>
<DOCTYPE! html>
<html>
<head>
<title><?php echo $minfo['name']; ?></title>
<meta charset="utf-8">
</head>
<body>
<h1>Welcome to my page</h1>
</body>
</html>
If its needed I can also include the "DATABASE.PHP" script.
Try this:
<?php
include "/database.php";
?>
<!DOCTYPE html>
<head>
<title><?php echo $minfo['name']; ?></title>
<meta charset="utf-8">
</head>
<body>
<h1>Welcome to my page</h1>
</body>
</html>
Assumes that $minfo['name'] is defined in your database.php.

PHP files which I have include doesn't appear in php file

ANSWER: Was a problem with web hosting.
This is my code
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" lang="en" content="Test Website " />
<meta name="author" content="">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title</title>
</head>
<body>
<section id="wrapper">
<?php include('includes/topHeader.php'); ?>
<?php include('includes/leftSide.php'); ?>
<?php include('includes/middleSide.php'); ?>
<?php include('includes/rightSide.php'); ?>
</section>
<?php include('includes/foot.php'); ?>
</section>
</body>
</html>
question the other php files not appear in the main page?
to create it I have use this website
http://www.1stwebdesigner.com/css/how-to-create-php-website-template/
Update
View Source shows:
<section id="wrapper">
<!--?php include('../includes/topHeader.php'); ?-->
<!--?php include('../includes/leftSide.php'); ?-->
<!--?php include('../includes/middleSide.php'); ?-->
<!--?php include('../includes/rightSide.php'); ?-->
</section>
<!--?php include('../includes/foot.php'); ?-->
You are using the include function right, so please make sure that:
Files you are trying to include really exists, you can test with file_exists function
You don't have any fatal errors somewhere in the files that stops the execution of your program (you can check error log)
Your markup is well formatted (in some cases when code is not formated correctly browsers cannot render the page correctly)
On a quick note apart from what was already suggested. Try
<?php include('../includes/topHeader.php'); ?>
<?php include('../includes/leftSide.php'); ?>
<?php include('../includes/middleSide.php'); ?>
<?php include('../includes/rightSide.php'); ?>
I say this with an assumption that the include folder resides above the current file in the folder structure.

Categories