您的位置:首页 > 编程语言 > PHP开发

2014.01.07php简单计算器制作

2014-01-07 23:40 525 查看
<?php
header('content-type:text/html;charset=utf-8');
$num1=true; //判断是否为真
$num2=true; //判断是否为真
$message=""; //设置为空
if(isset($_GET['submit'])){
if($_GET['num1']==''){
$num1=false;
$message.='第一个数字不能为空';
}
if($_GET['num2']==''){
$num2=false;
$message.='第二个数字不能为空';
}
if($num1 && $num2){
$sum=0;
switch($_GET['ysf']){
case '+':
$sum=$_GET['num1']+$_GET['num2'];
break;
case '-':
$sum=$_GET['num1']-$_GET['num2'];
break;
case 'x':
$sum=$_GET['num1']*$_GET['num2'];
break;
case '/':
$sum=$_GET['num1']/$_GET['num2'];
break;
}
}
}

/*计算机制作*/
?>
<table align="center" border="1" width="500">
<caption><h1>计算机</h1></caption>
<tr>
<form action="jsq.php">
<td>
<input type='text' name='num1' value=''/>
</td>
<td>
<select name="ysf">
<option>+</option>
<option>-</option>
<option>x</option>
<option>/</option>

</select>
</td>
<td>
<input type='text' name='num2' value=''/>
</td>
<td>
<input type='submit' name='submit' value='计算'/>
</td>
</form>
</tr>
<?php
if(isset($_GET['submit']))
{

if($num1 && $num2){
echo"<tr><td colspan='5'>";
echo"计算结果为".$sum;
echo"</td></tr>";
}
else{
echo"<tr><td colspan='5'>";
echo $message;
echo"</td></tr>";
}
}

?>
</table>


注意:if(isset($_GET['submit']))书写
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: