<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>计算器</title>
</head>
<body>
<from action="" method="post">
<table width="300px" border="0">
<td>第一个数</td> <td><input type="text" name="num1"/></td>
<tr/>
<td>第二个数</td> <td><input type="text" name="num2"/></td>
<tr/>
<td>运算符</td>
<td>
<select name="oper"/>
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</td>
<tr>
<td colspan="2"><input type="submit" value="计算结果"/></td>
</tr>
</table>
</from>
</body>
</html>
快看上边的表单控件 写成from了。大写的各种尴尬
【myCall.php】
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>计算器</title>
</head>
<body>
<td>form 表单 写错了 携程from 。。。大写的尴尬,以后记住
</td>
<form action="result.php" method="post">
<table width="300px" border="0">
<td>第一个数:</td> <td><input type="text" name="num1"/></td>
<tr/>
<td>第二个数:</td> <td><input type="text" name="num2"/></td>
<tr/>
<td>运算符</td>
<td>
<select name="oper"/>
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</td>
<tr>
<td ><input type="submit" value="计算结果"/></td>
</tr>
</table>
</form>
</body>
</html>
【result.php】
<?php
//接收用户从myCall.php界面过来的值
//1、接收num1
//$_REQUEST 该方法可以接收用户的post或者get请求数据
$num1=$_REQUEST['num1'];
//2、接收num2
$num2=$_REQUEST['num2'];
//3、接收运算符
$oper=$_REQUEST['oper'];
echo "接收到num1= ".$num1."接收到num2= ".$num2."接收到运算符= ".$oper;
echo "<br/>";
switch($oper){
case "+":
echo "结果:".($num1+$num2);
break;
case "-":
echo "结果:".($num1-$num2);
break;
case "*":
echo "结果:".($num1*$num2);
break;
case "/":
echo "结果:".($num1/$num2);
break;
}
?>
<a href="myCall.php">跳转回计算页面</a>
在result界面 $_REQUEST[‘xx’]; xx参数如果写错了 那么就接收不到前届满传递过来的值,系统会提示 undefined index :xx 类似提示,所以一般情况下写完最好排查下
练习题:
九九乘法表:
<?php
for($i=1;$i<=9;$i++){
echo "<br/>";
for($j=1;$j<=$i;$j++){
echo "$j"."*"."$i"."=".$i*$j;
echo " ";
}
}
?>
效果: