PHP code in HTM not being executed?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bob Kellock
Forum Newbie
Posts: 10
Joined: Fri Oct 30, 2009 10:57 am
Location: Wiltshire, UK

PHP code in HTM not being executed?

Post by Bob Kellock »

I'm a complete novice to PHP so please excuse what is probably a very simple question.

echo("Fred");
works correctly in a .PHP file but not in an HTM, e.g.
My name is <?php echo(" Fred "); ?> Bloggs
only displays My name is Bloggs.

According to http://php.about.com/od/advancedphp/p/html_php.htm it says I need to add
AddType application/x-httpd-php .html
Or
AddType application/x-httpd-php .htm
to my .htaccess file.

If I do that and then open the HTML page the browser (Opera) comes up with a pop-up to download the html file.

What should I be doing?

Bob
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: PHP code in HTM not being executed?

Post by akuji36 »

Hello

In order for php engine to recognize and process embedded php in html

form the entire file must be saved in php format ex

example.php

in example php file

you may write your html form

and include php.

thanks

Rod
Bob Kellock
Forum Newbie
Posts: 10
Joined: Fri Oct 30, 2009 10:57 am
Location: Wiltshire, UK

Re: PHP code in HTM not being executed?

Post by Bob Kellock »

Thanks, Rod.

I'd tried that but it simply puts up the message "No input file specified".

What sort of input file is wanted?

Bob
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: PHP code in HTM not being executed?

Post by akuji36 »

Here's an example of php embedded in html form.


Note in this case all code is on one page
(sometimes the user is directed to another page which processes all the php code).

http://www.ntchosting.com/php/php-in-html.html

thanks

Rod
Post Reply