i wanna get two inputs and calculate them. how can i do?

my code is

<input type="text" name="a" />
<input type="text" name="b" />
<input type="submit" name="Submit" value="calculate" />
 <?php
if ($a > $b)
    echo "a is greater than b";
	else echo "a is greater than b"
?>

please help me

You need to learn more about HTML forms

Click here to see more about how to retrieve the data from the form in your php program.

You should definitely do some more reading on this as chrishea has suggested and provided links to. However, here's a quick example using two files for clarity, but it can easily be done using one file also.

form.html:

<form action="process.php" method="post">
  <input type="text" name="a" />
  <input type="text" name="b" />
  <input type="submit" name="Submit" value="calculate" />
</form>

process.php:

<?php
  $a = $_POST['a']; // Get the value submitted for "a"
  $b = $_POST['b']; // Get the value submitted for "b"
  if ($a > $b)
  {
    echo "a is greater than b";
  }
  else
  {
    echo "a is greater than b";
  }
?>

thanx for helping but i open the file, at the next of calculate "a is greater than b" is writed.
how i can solve that?
and i change process.php to index.php

put this in process.php

<?php
if($_SERVER['REQUEST_METHOD']== "POST")
{
  $a = $_POST['a']; // Get the value submitted for "a"
  $b = $_POST['b']; // Get the value submitted for "b"
  if ($a > $b)
  {
    echo "a is greater than b";
  }
  else
  {
    echo "a is greater than b";
  }
}
?>

thanx you so much it works.
i attribute so much but i wanna know someting more:
i wanna define c which (a-b)*(a+b) and show here
how i can?

$c =($a-$b)*($a+$b);
echo $c;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.