interface.php
123<meta charset= "Utf-8"/>4<title> This is a simple calculator </title>56<body>789<form action= "operation.php" method= "POST" Name= "interface" >Ten<table> One<tr><td> Please enter the first number: </td><td><input type= "text" name= "NUM1" value= "/></td></ Tr> A<tr><td> Select the operation symbol:</td> -<td><select name= "Symbol" > -<option value= "+" >+</option> the<option value= "-" >-</option> -<option value= "*" >*</option> -<option value= "/" >/</option> -</select> +</td> -</tr> +<tr><td> Please enter a second number: </td><td><input type= "text" name= "num2" value= "/></td></ Tr> A<tr> at<td><input type= "Submit" value= "Calculation results"/></td> -</tr> -</table> -</form> -<?PHP - //Empty to determine if the accepted value is null isset to determine if the accepted value exists in if(isset($_get[' errno '])){ - $erro=$_get[' errno ']; to if($erro==1){ + Echo"<br><font size= ' 4 ' color= ' red ' > input is not a number or is empty, please re-enter! </font> "; - } the } * //determine if an integer variable exists $ if(isset($_get[' Sum '])){Panax Notoginseng $sum=$_get[' Sum ']; - Echo"<br><font size= ' 3 ' color= ' red ' > Operation result is".$sum." </font> "; the } + //determine if a number exists A if(isset($_get[' Dividend '])){ the $dividend=0; + Echo"<br><font size= ' 3 ' color= ' red ' > Dividend cannot be".$dividend." </font> "; - } $?> $</body> -
operation.php
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8" ><?PHPrequire_once"Operation.class.php"; $num 1=$_post[' Num1 ']; $num 2=$_post[' Num2 ']; $symbol=$_post[' symbol ']; //encapsulate the following operations into an operation class $oper 1=NewOper (); $sum=$oper 1->operation ($num 1,$num 2,$symbol); Header("location:interface.php?sum=$sum"); ?>
operation.class.php
<?PHP//a class for a calculator operation require_once"Operation.php";//referencing a file classoper{functionOperation ($num 1,$num 2,$symbol){ //determine if it is a digital is_numeric if( (Is_numeric($num 1) &&Is_numeric($num 2)) ){ if($symbol= = ' + '){ $sum=$num 1+$num 2; } if($symbol= = '-'){ $sum=$num 1-$num 2; } if($symbol= = ' * '){ $sum=$num 1*$num 2; } if($symbol= = '/'){ if($num 2==0){ Header("location:interface.php?dividend=$num 2"); Exit(); }Else{ $sum=$num 1/$num 2; } } return $sum; }Else{ Header("Location:interface.php?errno=1"); Exit(); } } }?>
Interface diagram
Less familiar JavaScript drip, slowly moving forward, with simple complication of PHP small calculator a copy