如何在php文件中编写html代码

如何在php文件中编写html代码,php,html,Php,Html,我想在login.php中编写一个html表单,并在login.php中提交。那么如何在这个php文件中编写html呢?如果我编写标记,它会显示错误。 <?php // php code here ?> html code here <?php // more php code here ?> more html code here 这里是html代码 更多的html代码在这里 如果计划在文件中的任何位置使用php代码,请使用.php文件扩展名。请确保首先使用以

我想在login.php中编写一个html表单,并在login.php中提交。那么如何在这个php文件中编写html呢?如果我编写标记,它会显示错误。


<?php
// php code here
?>

html code here

<?php
// more php code here
?>

more html code here
这里是html代码 更多的html代码在这里

如果计划在文件中的任何位置使用php代码,请使用.php文件扩展名。

请确保首先使用以下扩展名命名文件:
.php
,以便服务器可以解析代码。 然后,将处理表单的PHP代码放在
HTML
代码之前。 编写
HTML
表单

最后,如果您希望在提交表单时(且仅在提交表单时)执行PHP代码,请执行以下过程:

<?php
if(!empty($_POST)) // which is the same as doing if($_POST); be sure not to use isset() function as $_POST variable is always set
{
    // do the form processing
}
?>
<html>
    <!-- your HTML markup -->
    <form action="" method="post"> <!-- << leave action attribute blank to submit the form to the very same page -->
        <!-- your form -->
    </form>
</html>