如何在从HTML调用时在Windows上执行php代码

I am very new to PHP and HTML as well. I have written html code to read first name and last name as:

<!DOCTYPE html>
<html>
<body>
<form action="welcome.php" method="post">
First Name: <input type="text" name="Fname"><br>
Last Name: <input type="text" name="Lname"><br>
<input type="submit">
</form>
</body>
</html>

and I am calling welcome.php to insert some values into database as below.

<html>
<body>
Welcome <?php echo $_POST["Fname"]; ?>
<?php $db = pg_connect("host=localhost port= dbname= user= password="); ?>
<?php $query = "INSERT INTO employee VALUES ('sasi','kala')"; ?>
<?php $result = pg_query($query); ?>
?>
<a href="first.html"></a>
</html>
</body>

when I open html file by chrome browser, I am getting 2 fields as FirstName and LastName. After entering details and click on submit button, nothing is getting displayed or executed in php. If i remove html and body tag from php file, entire code is getting displayed on browser.How can i run this PHP script from HTML using my web browser. Any installation needed? Am i doing anything wrong. I am executing this code in windows web browser. Can anyone tell me the procedure?

You are closing </html> tag to early, you must need to follow this:

<html>
<body>
// your inner html
</body>
</html>

One more thing, you also have extra closing php tag ?> after this line, i hope this is just a typo:

<?php $result = pg_query($query); ?>

There are so many tutorials available on internet for you, one of: http://www.w3schools.com/html/

One more thing, if you want to use user input in your SQL Statement than note that, your query is open for SQL injection, you must need to prevent your query, this will help you: How can I prevent SQL injection in PHP?

You need to install a web-server on your computer, and ensure that it includes the PHP parser.
This is because PHP is a server-side scripting language, as opposed to the client-side language JavaScript. So when you browser sees the PHP tags it doesn't know what they are, and thus promply ignores them (and their content, the actual PHP code). Which is also why you see the PHP code when you remove the HTML tag, as you're telling the browser that it's just plain text content at this point.

There are many popular packages for Windows when it comes to all-inclusive web-servers, WAMP being one of them.

PS: Ensure that you do not make this web-server accessible from the internet, as you will have all kinds of attacks performed against your computer then!