0

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

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Shanti C
1

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";
  }
?>
0

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

0

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";
  }
}
?>
0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.