一个表单问题

fdsh 2003-11-29 11:21:43
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算器</title>
</head>
<?php
$calculator_ids = array("+","-","*","/");
if(isset($calculator_ids)){
switch($calculator_ids){
case "+": $result=$num1+$num2; break;
case "-": $result=$num1-$num2; break;
case "*": $result=$num1*$num2; break;
case "/": $result=$num1/$num2; break;
}
}
?>
<body>
<form action="jisu1.php" method="post">
第一个数:<input name="num1" type="text" size="10" maxlength="10">
第二个数:<input name="num2" type="text" size="10" maxlength="10"><br><font face="Arial, Helvetica, sans-serif"></font>
<input name="jishu" type="radio" value="<?php $calculator_ids[0] ?>" checked>+<br>
<input name="jishu" type="radio" value="<?php $calculator_ids[1] ?>" >-<br>
<input name="jishu" type="radio" value="<?php $calculator_ids[2] ?>" >*<br>
<input name="jishu" type="radio" value="<?php $calculator_ids[3] ?>" >/<br>
结果是<?php echo $result?><br>
<input name="" type="submit" value="计算">
<input name="" type="reset" value="重新">
</form>
</body>
</html>
计算不出来
...全文
82 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fdsh 2003-11-29
  • 打赏
  • 举报
回复
多谢!!放分!
feel8 2003-11-29
  • 打赏
  • 举报
回复
$_POST['var'];
类似这样得到post来的变量值。
azhilaoa 2003-11-29
  • 打赏
  • 举报
回复
错误太多。

改成这样:

===============jisu1.php==================
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算器</title>
</head>
<?php
$calculator_ids = array("+","-","*","/");

switch($_POST['jishu']){
case "+": $result=$_POST['num1']+$_POST['num2']; break;
case "-": $result=$_POST['num1']-$_POST['num2']; break;
case "*": $result=$_POST['num1']*$_POST['num2']; break;
case "/": $result=$_POST['num1']/$_POST['num2']; break;
}
?>
<body>
<form action="jisu1.php" method="post">
第一个数:<input name="num1" type="text" size="10" maxlength="10">
第二个数:<input name="num2" type="text" size="10" maxlength="10"><br><font face="Arial, Helvetica, sans-serif"></font>
<input name="jishu" type="radio" value="<?php echo $calculator_ids[0] ?>" checked>+<br>
<input name="jishu" type="radio" value="<?php echo $calculator_ids[1] ?>" >-<br>
<input name="jishu" type="radio" value="<?php echo $calculator_ids[2] ?>" >*<br>
<input name="jishu" type="radio" value="<?php echo $calculator_ids[3] ?>" >/<br>
结果是<?php echo $result?><br>
<input name="" type="submit" value="计算">
<input name="" type="reset" value="重新">
</form>
</body>
</html>
==============jisu1.php END================

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧