为什么我的PHP计算器没有给变量赋值竟然能运行?
计算器链接http://www.physun.sdu.edu.cn/1.htm第一部分<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Tra...
计算器链接http://www.physun.sdu.edu.cn/1.htm
第一部分
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>计算器</title>
</head>
<body>
<form action="1.php" method="post">
<input type="text" size="4" name="a" />
<select name="caculate">
<option value="1">+
<option value="2">-
<option value="3">*
<option value="4">/
</select>
<input type="text" size="4" name="b" />
</br>
</br>
<input type="submit" value="上交啦~~~~" /> <input type="reset" value="弄错了,再来一遍" />
</form>
</body>
</html>
第二部分
答案是:
<h1>
<?php
if ($caculate == "1")
{$x = $a + $b;
print $x;}
elseif ($caculate == "2")
{$x = $a - $b;
print $x;}
elseif ($caculate == "3")
{$x = $a * $b;
print $x;}
else
{$x = $a / $b;
print $x;}
?>
</h1> 展开
第一部分
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>计算器</title>
</head>
<body>
<form action="1.php" method="post">
<input type="text" size="4" name="a" />
<select name="caculate">
<option value="1">+
<option value="2">-
<option value="3">*
<option value="4">/
</select>
<input type="text" size="4" name="b" />
</br>
</br>
<input type="submit" value="上交啦~~~~" /> <input type="reset" value="弄错了,再来一遍" />
</form>
</body>
</html>
第二部分
答案是:
<h1>
<?php
if ($caculate == "1")
{$x = $a + $b;
print $x;}
elseif ($caculate == "2")
{$x = $a - $b;
print $x;}
elseif ($caculate == "3")
{$x = $a * $b;
print $x;}
else
{$x = $a / $b;
print $x;}
?>
</h1> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询