PHP Calculator not working as expected -


i have created php calculator when try divide 2 numbers multiplies them

link code=http://pastebin.com/raw.php?i=9qtmjmqy

<?php  ?>  <html> <body>  <?php if(isset($_get['page'])){ $page = $_get['page']; } else{ $page = ''; }  class calc{     var $number1;     var $number2;           function add($number1,$number2)         {             $result = $number1 + $number2;             echo("the sum of $number1 , $number2 $result<br><br>");             echo("$number1 + $number2 = $result");             exit;             }          function subtract($number1,$number2)         {             $result = $number1 - $number2;             echo("$number1 subtract $number2 $result<br><br>");             echo("$number1 - $number2 = $result");             exit;             }          function multiply($number1,$number2)         {             $result  = $number1 * $number2;             echo("$number1 multiplied $number2 $result<br><br>");             echo("$number1 * $number2 = $result");             exit;             }          function divide($number1,$number2)         {             $result = $number1 / $number2;             echo("$number1 divided $number2 $result<br><br>");             echo("$number1 / $number2 = $result");             exit;         } } $calc = new calc();             ?>  <title>php object oriented calculator</title> <form name="calc" action="?page=calc" method="post"> number 1: <input type=text name=value1><br> number 2: <input type=text name=value2><br> operation:  <input type=radio name=oper value="add">addition  <input type=radio name=oper value="subtract">subtraction  <input type=radio name=oper value="divide">division <input type=radio name=oper value="multiply">multiplication<br> <input type=submit value="calculate"> </form>   <?php if($page == "calc"){ $number1 = (int)$_post['value1']; $number2 = (int)$_post['value2']; $oper = $_post['oper'];     if(!$number1){         echo("you must enter number 1!");         exit;         }         if(!$number2){             echo("you must enter number 2!");             exit;             }         if(!$oper){             echo("you must select operation numbers!");             exit;             }          if($oper == "add"){             $calc->add($number1,$number2);             }          if ($oper =="subtract"){             $calc->subtract($number1,$number2);             }         if ($oper = "multiply"){             $calc->multiply($number1,$number2);             }         if ($oper = "divide"){             $calc->divide($number1,$number2);             }             }             ?> </body> </html> 

you using assignment instead of comparison

your code (wrong!):

if ($oper = "multiply") 

right code (what want do):

if ($oper == "multiply") 

the same division.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -