什么是REQUEST方式
代表浏览器通过”get”方式或”post”方式提交的数据
代码示例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <?php $num1 = ''; $num2 = ''; $result = ''; if (isset($_REQUEST['num1'])) { $num1 = $_REQUEST['num1']; $num2 = $_REQUEST['num2']; $result = $num1 + $num2; // echo "计算结果:",$result; } ?> <body> <!-- action留空,表示提交给自己(本页) --> <form action="" method="get"> <!-- get和post同时提交: action中的地址?后的数据就是get数据 form中的各个表单项就是post数据 --> <input type="text" name="num1" value="<?php echo $num1; ?>"> <!-- 可用下拉列表select代替 供用户选择加减乘除 --> + <input type="text" name="num2" value="<?php echo $num2; ?>"> <input type="submit" value="="> <input type="text" name="result" value="<?php echo $result; ?>"> </form> </body> </html>
暂无评论