Please see what's wrong with my code

php

#1

This is what I have typed. For this form method I want to get the answer in the answer input field. The php is not working. I can't understand what's wrong

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>

  <form action="index.html" method="get">
       <h1>Calculator</h1>
       <a>Num 1</a>&nbsp;&nbsp; <input type="text" name="num1" value=""><br><br>
       <a>Num 2</a>&nbsp;&nbsp; <input type="text" name="num2" value=""><br><br>
       <a>Answer</a>&nbsp; <input type="text" name="ans" value=""><br><br>
       <button type="button" name="add">+</button>
       &nbsp;&nbsp;&nbsp; <button type="button" name="subtract">-</button>
       &nbsp;&nbsp;&nbsp; <button type="button" name="multiply">*</button>
       &nbsp;&nbsp;&nbsp; <button type="button" name="devide">/</button>
     </form>
</body>
</html>
<?php
if (isset($_GET["add"])) {
  $number1 = $_GET['num1'];
  $number2 = $_GET['num2'];
  $answer = $_GET['ans'];

  $_GET['ans'] = $_GET['num1'] + $_GET['num2'];
  $_GET['ans'];
 }

   ?>

#2

I'm still trying to get a grasp of the code, so will respond presently. However, one question comes to mind. Is this running on a live server? Does the domain have an .htaccess or configuration that stipulates to parse HTML for PHP?

Without a server config or directive HTML will never get parsed for PHP. Change the action resource to index.php and this problem is worked around with no configuration or directive (the best route).

Edit...

One would only configure a server to treat HTML as PHP on a legacy site. When the configuration is done on the server itself, there is no performance hit. When it is done with .htaccess, though, there is a big performance hit, if anyone is measuring. Servers can take almost every configuration, including domain restrictions and redirects. When .htaccess is used for these purposes, like it or not, the entire domain and all its sub-directories get populated with .htaccess files, and they get opened on every traversal of the directory structure when handling requests.


#3

Second question, moving on to more pertinent concerns, why GET? Why not, POST?

http://www.tutorialspoint.com/php/php_get_post.htm