putting PHP inside a HTML page. - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-20-2011, 06:55 AM   #1 (permalink)
Junior Member
 
Join Date: Oct 2010
Posts: 9
Default putting PHP inside a HTML page.

Hello,

As far as I know I can add PHP inside a HTML page, all I need to do is open <?php and close ?> when I am finished. But now I am adding some php code to a .html page to upload an image to the database and for some strange reason as soon as the server finds a > (not a ?>) then it thinks the php code is finished and stops executing. Please find an extract of the code bellow:

I've uploaded the page on glcalcados.com.br/labs/oportunidades.html and you can see the code breaks on ($imagem_size > 0) as if the > made the server think that is the end of the php code... could someone please help?

Thanks


<body>

<!-- bellow is the code to upload the cadidates image -->
<?php
require_once('fotoappvars.php');
require_once('connectvars.php');

if (isset($_POST['submit'])) {
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// Grab the descricao data from the POST
$imagem = mysqli_real_escape_string($dbc, trim($_FILES['foto']['name']));
$imagem_type = $_FILES['foto']['type'];
$imagem_size = $_FILES['foto']['size'];

// Check the CAPTCHA pass-phrase for verification

if (!empty($imagem)) {
if ((($imagem_type == 'image/gif') || ($imagem_type == 'image/jpeg') || ($imagem_type == 'image/pjpeg') || ($imagem_type == 'image/png')) && ($imagem_size > 0) && ($imagem_size <= GW_MAXFILESIZE)) { if ($_FILES['imagem']['error'] == 0) { // Move the file to the target upload folder
$target = GW_UPLOADPATH . $imagem;
if (move_uploaded_file($_FILES['foto']['tmp_name'], $target)) {
// Write the data to the database
$query = "INSERT INTO fotos(foto) VALUES ('$imagem')";
mysqli_query($dbc, $query);

// Clear the score data to clear the form
$imagem = "";

mysqli_close($dbc);
}
else {
echo '<p class="error">Houve um problema e a sua foto nao foi enviada, favor nos contatar</p>';
}
} } else { echo '<p class="error">A imagem deve ter como extensao GIF, JPEG, ou PNG e nao ser mais pesada do que ' . (PROMOCOES_GW_MAXFILESIZE / 1024) . ' KB in size. Contate-nos para maiores informacoes</p>'; }

// Try to delete the temporary screen shot image file
@unlink($_FILES['imagem']['tmp_name']);
}
else {
echo '<p class="error">Por favor preencha todos os campos</p>';
}
}
?>
luizarios is offline   Reply With Quote
Sponsored Links
Old 07-21-2011, 04:21 AM   #2 (permalink)
Junior Member
 
Join Date: Oct 2010
Posts: 9
Default Re: putting PHP inside a HTML page.

so, I got no reply but after looking at Google for a day I found out what went wrong so I thought I'd post here the resolution for anybody who needs was having the same problem.

my server was simply not parsing php inside HTML (not reading php inside .html files) , this page has more details on how to fix it:

desilva.biz/php/phpinhtml.html

webmasterworld.com/forum88/3921.htm

Last edited by luizarios; 07-21-2011 at 05:08 AM.
luizarios is offline   Reply With Quote
Old 07-21-2011, 04:40 AM   #3 (permalink)
Junior Member
 
Join Date: Oct 2010
Posts: 9
Default Re: putting PHP inside a HTML page.

Harry,

thanks for your reply. I've resolved the matter by changing the .htaccess file and now it's fine.
luizarios is offline   Reply With Quote
Old 07-21-2011, 05:00 AM   #4 (permalink)
Regular User
 
Join Date: May 2011
Location: Germany
Posts: 103
Default Re: putting PHP inside a HTML page.

your server might not recognize a *.html page as a *.php page. If you use php within html sites, you'd better make the name *.php.
Riesling is offline   Reply With Quote
Old 07-21-2011, 05:06 AM   #5 (permalink)
Junior Member
 
Join Date: Oct 2010
Posts: 9
Default Re: putting PHP inside a HTML page.

Hello,

You are correct, my server was not reading the php but this can be resolved, the solution in those sites:

desilva.biz/php/phpinhtml.html

webmasterworld.com/forum88/3921.htm

having the page as .php is not always easy as I'd have to echo the whole html code.

Thanks for your reply
luizarios is offline   Reply With Quote
Old 07-21-2011, 08:43 AM   #6 (permalink)
Regular User
 
Join Date: May 2011
Location: Germany
Posts: 103
Default Re: putting PHP inside a HTML page.

Quote:
Originally Posted by luizarios View Post
having the page as .php is not always easy as I'd have to echo the whole html code.
No, you do not have to. Just rename the site. You can write the html as usual and insert the php-Code with
<? php

?>
where you need it. It is really that easy!
Riesling is offline   Reply With Quote
Old 07-21-2011, 10:50 PM   #7 (permalink)
Regular User
 
Laugh's Avatar
 
Join Date: Jul 2011
Posts: 42
Send a message via AIM to Laugh
Default Re: putting PHP inside a HTML page.

What did you change in the .htaccess file?
Laugh is offline   Reply With Quote
Old 07-22-2011, 04:00 AM   #8 (permalink)
Junior Member
 
Join Date: Oct 2010
Posts: 9
Default Re: putting PHP inside a HTML page.

Laugh,

That's what I added to .htaccess


#RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
luizarios is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 04:55 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting