-3

i have calculator buttons type submit...i got the values and displaying in on the same page...but unable to add the addition functionality to the two numbers. here is my code dont know what to do next..two numbers from user and displaying the result only.

    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
        <input type="submit" value="0" name="zero">
        <input type="submit" value="1" name="one">
     </form>

<?php 
   if (isset($_POST["zero"]))
   {
        $a = $_POST["zero"];
        echo $a;
   }
   if (isset($_POST["one"]))
   {
        echo $_POST["one"];
   }
?>
user2500189
  • 47
  • 1
  • 1
  • 3
  • Are you planning not to use ajax ? – 0x_Anakin Jun 19 '13 at 10:30
  • 1
    each of your buttons is requesting the script to reload by passing it a value of 0 or 1, where is the arithmetic operations? what defines add or minus. ? – DevZer0 Jun 19 '13 at 10:32
  • @ircmaxell provided excellent PHP code for evaluating calculations [here](http://stackoverflow.com/questions/12692727/how-to-make-a-calculator-in-php) – Mark Baker Jun 19 '13 at 10:52

1 Answers1

1

The following code will display the value of both variables added together.

<?php 
  if (isset($_POST["zero"]) && isset($_POST["one"]))
  {
    $z = $_POST["zero"];
    $o = $_POST["one"];
    echo ($z+$o);
  }
?>

Although I'm not sure why your input fields have values of "1" and "0", they should be defined by a text box like so;

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
  <input name="zero" type="text" />
  <input name="one" type="text" />
  <input type="submit">
</form>
Craigy Craigo
  • 218
  • 2
  • 11