php is used to realize adding subtracting multiplying and dividing calculator
- 2020-12-07 03:59:20
- OfStack
Use php to add, subtract, multiply and divide calculator. The code is simple!
<?php
header("content-type:text/html;charset=utf-8");
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title> Simple computer </title>
</head>
<body>
<form action="jisuan.php" method="post">
The first 1 The number of <input type="text" value="" name="num1"><br />
Calculation of symbols <select name="oper">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select><br />
The first 2 The number of <input type="text" value="" name="num2"><br />
<input type="submit" value=" The calculation results "><br />
</form>
</body>
</html>
<?php
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$oper=$_POST['oper'];
$rs=0;
switch($oper){
case "+":
$rs=$num1+$num2;
break;
case "-":
$rs=$num1-$num2;
break;
case "*":
$rs=$num1*$num2;
break;
case "/":
$rs=$num1/$num2;
break;
default: echo " You have not entered correctly ";
}
$_SESSION['rs']=$rs;
echo ' The calculated results are as follows: '.$_SESSION['rs'];
?>