douqihou7537 2012-11-08 18:06
浏览 25
已采纳

Php表单在填写时不会发布结果

First of all, I am not en expert at programming, so please explain things a bit if you can so I can understand them better. I am trying to make a calculator that will have some fields the user can fill out, and will display the last output. Basically this:

Variable boxes "Go" button Results display here after Go is pressed.

And the user can change the boxes and click go again to refresh with the new results.

I do not want to use Java for this if at all possible. Please help me with an HTML/PHP solution.

I have this page nammed "isset.php"

<?php 
session_start(); 
error_reporting(E_ALL);
ini_set('display_errors', '1');?>
<!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>
</head>
<body>

<?php
     if(isset($_POST['submit']))
        {
        $a = $_POST['a'];
        $b = $_POST['b']; 
        $sf = $a-(2*$b);
        echo "<br><br>Safety Factor is ";
        echo $sf;
        } 
     else {
        echo "Your results will display here after you use the calculator.";
          }
 ?>

 <br>Calculator
 <form name="submit" method="post" action="isset.php">
 <table width="450px">
     <td valign="center">
     <label for="a">a</label></td>
        <td valign="center">
        <input type="text" name="a" value="45"></td></tr>
     <td valign="center">
     <label for="b">b</label></td>
        <td valign="center">
        <input type="text" name="b" value="16"></td></tr>         
 <tr><td colspan="2" style="text-align:center">
 <input type="submit" value="Calculate!">
 </td></tr></table>
 </form>        

</body>
</html>
  • 写回答

2条回答 默认 最新

  • douhuanglou1445 2012-11-08 18:08
    关注

    Change <input type="submit" value="Calculate!"> to <input name="submit" type="submit" value="Calculate!">

    The reason your code is not working is because you're checking to see if the post data contains the key submit but you haven't defined it within your form (you do this by adding a name attribute).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧