OK, this is as basic a question as any of you will get on this site. Here's the deal. I have a very basic PHP file saved, of course, as php. I have an HTML page built in Dreamweaver. So, how do I include that file in the HTML so that it is executed? The PHP file is a simple Hello World (I told you this was basic).
<php?
print("Hello World!");
php?>
Pretty simple stuff I know. But I don't know what I have to do or where I have to place this file within the HTML to get it to execute. I'm just getting a blank page. If someone could give me an example of what the HTML looks like with a php file, that would be great. Thanks in advance.

php?> becomes ?>

and

<php? becomes <?php

give that a try

Thank you for the quick response. Let see if I understand, though.

Let's say I have some basic HTML.

<html>
<head>
  blah blah
</head>

<body>
  
  <php? becomes Hello_World.php<?php

</body>
</html>

I've never seen php code like that before. I can't believe how much trouble I'm having with something that seems so simple. I thought learning the language was going to be the hard part.

Also be sure to rename your file from *.html/*.htm to *.php or the PHP code will not execute, it'll display as text.

So rename index.htm to index.php? That I didn't try, and never would have guessed. Thank you

sorry i didnt mean to confuse things... try this below:

<html>
<head>
  blah blah
</head>

<body>
  
  <?php ALL YOUR PHP CODE GOES HERE ?>

</body>
</html>

And then just make sure your file has a .php extension!

<html>
<head>
<title>Blah</title>
</head>
<body>
Blah Blah,<br />
<?php include("helloworld.php"); ?>
</body>
</html>

helloworld.php is:

<?php echo "Hello World!"; ?>

Anytime you want to run PHP code the file has to end with the extension .php to let PHP know it's a file that has to be examined.

What PHP does is goes through your source file and creates an output HTML file that is sent to the client browser. So anytime the PHP parser sees the codes <?php and php?> or <?php ?> it executes the PHP code between the two tags and whatever the code tells it to output to HTML winds up in the file that is sent to the browser.

Aha! I didn't know that's how it worked at all. I thought you write the php in a separate file and then include it within the html file somehow. I'll give this a shot. Thanks so much.
Out of curiosity, is there a way to write the code in a separate php file and include it within a html file? I can't imagine that all the code involved in building and querying a database is written inside what amounts to an html file. Again, I'm as new to this as it gets, but that seems unlikely to me. I spoke to web host and they told me to upload the php file to my "public_html folder" and it will execute from their once it's referenced in the html file. Is that not right.

This is what I have in the body of my doc (I didn't include the head because it doesn't seem relevant):

<body>
	
	<php?
		echo "Hello World. You suck!"; ?>
		
</body>

I have it saved as a php file. This is the link http://haciendocoro.com/PHP_Info.htm

As you can see, it's essentially a blank page. Only the blue background shows up. The url still says it's in htm, but I have it saved as php. If it matters, I'm actually using FrontPage for this site (though I'm sure that's irrelevant).

check this link to learn more about php

Thanks for the post, but I have a PHP book I blew $30 on already. I can learn the language, that I can do. I just can't get the damn thing to show up a web page.

Are you sure that the hosting provider supports PHP?

Are you sure that the hosting provider supports PHP?

Yeah it does. I used PHP in a pseudo search bar. I get how to use it in that case. But in the course of an html page I'm not seeing how to get the php to execute when it simply on its own. It simply doesn't show up.

Personally i hate Frontpage and there's nothing better than Notepad++ for the PC, you just need to make sure the file extension is .php and if its not, its not going to process the PHP before outputting the HTML, also check your Web host has PHP enabled...

Sorry just saw your web host supports PHP as i posted my reply...

Personally i hate Frontpage and there's nothing better than Notepad++ for the PC, you just need to make sure the file extension is .php and if its not, its not going to process the PHP before outputting the HTML, also check your Web host has PHP enabled...

I agree 100% about FrontPage, but it came free on the PC. I have just begun using Dreamweaver, which along with the rest of CS5, is 1000 times better. And yes, php is enabled. Thanks for the comment

Well, you call your page xxx.php
and wherever you want to use php you just say

<?php  ?>

that's basicly it...
Example:

<?php echo "hello world..."; ?>

This is what I have in the body of my doc (I didn't include the head because it doesn't seem relevant):

<body>
	
	<php?
		echo "Hello World. You suck!"; ?>
		
</body>

OK, but:
a. The name of the file need to end in ".php"
b. You MUST use the proper php tag delimiters:
WRONG: <php? (this is what you have)
CORRECT: <?php

<? php
echo "hello world";


?>

how to make a text box in php and button?When the button click,appear the new web page

Member Avatar for P0lT10n

how to make a text box in php and button?When the button click,appear the new web page

you can doit without php... if you want to go to X page that was wrote in the txt, you can use JavaScript, example:

<html>
<head>
     <title>JavaScript</title>
<script type="text/javascript">
function openWebpage(){
     if(document.getElementById('page').value != '' or document.getElementById('page').value != null){
          window.location=document.getElementById('page').value;
     }else{
          alert("Error: Write a page to go...");
     }
}
</head>
<body>
<input type"text" name"page" id="page" />
<input type="button" name="button" onclick="openWebpage()" value="Go to" />
</body>
</html>

This will redict you to the page you wrote in the txt input...

Create an application that reads in a five-digit integers and determines whether it is a palindrome.If the number is not five digits long,display an error messsage and allow the user to enter a new value in java...thanks a lot.

how about using php?the textbox and the button.

Member Avatar for P0lT10n

how about using php?the textbox and the button.

for that:

<html>
<head>
<title>Your title</title>
</head>

<body>
<?
if($_SERVER['REQUEST_METHOD']=="POST"){
	echo "<meta http-equiv='Refresh' content=\"2; url='http://".$_POST['page']."'\"/>";
}
?>
<form id="form1" method="post" action="">
		<input type="text" name="page" id="page" />
		<input name="button" type="submit" />
</form>
</body>
</html>

@Mickey23: Please don't hijack someone else's thread with irrelevant questions. Make your own threads...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.