我的第一个PHP程序
<html>
<head>
<title>
<?php
echo "我的计算器";
?>
</title>
</head>
<script type="text/javascript">
function Onclick()
{
var num1 = document.getElementById('num1').value;
var num2 = document.getElementById('num2').value;
if(num1=="")
{
alert("num1输入不正确");
}
if(num2=="")
{
alert("num2输入不正确");
}
if(num1==""||num2=="")
{
return false;
}
return true;
}
</script>
<body>
<center>我的计算器<br/>
<form action="index.php" method="post">
num1:<input type="text" id="num1" name="num1" value=""><br/>
num2:<input type="text" name="num2" value=""><br/>
计算方式:<select name="run">
<option value="+">加</option>
<option value="-">减</option>
<option value="*">乘</option>
<option value="/">除</option>
</select>
<input type="submit" name="submit"value="计算" onClick="return Onclick();"/><br/>
</form>
<?php
$num1 = $_POST['num1'];
$num2 =$_REQUEST['num2'];
$run = $_REQUEST['run'];
switch($run)
{
case '+':print("两数之和为:".($num1+$num2));break;
case '-':print("两数之差为:".($num1-$num2));break;
case '*':print("两数之乘积为:".($num1*$num2));break;
case '/':print("两数之和为:".($num1/$num2));break;
}
?>
</center>
</body>
</html>
本文出自 “ITeamsky-杨波的技术空间” 博客
补充:Web开发 , php ,