douchun1961
2014-08-23 11:41
浏览 80
已采纳

在PHP中使用$ _GET字符串计数

Hi Im trying to do few calculations but seems like my GET function isn't being used correctly in line 82 any assistance please. I'm a newbie with this coding...

Im trying to retrieve info from my form and add it all together in line 82

Form:

<!DOCTYPE HTML> 
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body> <form method="POST" action="gc.php"> 
Interceptors:<input type="text" name="inter" value="<?php echo $inter;?>"><br><br>
Destroyers:<input type="text" name="destr" value="<?php echo $destr;?>"><br><br>
Cruisers:<input type="text" name="cruiser" value="<?php echo $cruiser;?>"><br><br>
Bombers:<input type="text" name="bomb" value="<?php echo $bomb;?>"><br><br>
Battleships:<input type="text" name="battle" value="<?php echo $battle;?>"><br><br>
<input type="submit" name="submit" value="Submit"> 
</form><br><br><p></a>
</body>
</html>

Calculation page named gc.php

<html>
    <body>



    <!---Metal--->
    <?php
    $im = 120;
    $dm = 200;
    $cm = 1000;
    $bom = 2000;
    $bm = 3650;
    ?>

    <!---Crystal--->
    <?php
    $ic = 80;
    $dc = 160;
    $cc = 540;
    $boc = 840;
    $bc = 1900;
    ?>

        <!---Gas--->
    <?php
    $ig = 120;
    $dg = 150;
    $cg = 1360;
    $bog = 1450;
    $bg = 4970;
    ?>

       <!---Attack HP--->
    <?php
    $ia = 80;
    $da = 44;
    $ca = 300;
    $boa = 50;
    $ba = 1400;
    ?>

    <!---Defence HP--->
    <?php
    $id = 20;
    $dd = 110;
    $cd = 450;
    $bod = 10;
    $bd = 1180;
    ?>

        <!---Total Attack HP - Ship Type--->
    <?php
    $tia = ($_GET["inter"] * $ia);
    $tda = ($_GET["destr"] * $da);
    $tca = ($_GET["cruiser"] * $ca);
    $tboa = ($_GET["bomb"] * $boa);
    $tba = ($_GET["battle"] * $ba);
    ?>

    <!---Total Defence HP - Ship Type--->
    <?php
    $tid = ($_GET["inter"] * $id);
    $tdd = ($_GET["destr"] * $dd);
    $tcd = ($_GET["cruiser"] * $cd);
    $tbod = ($_GET["bomb"] * $bod);
    $tbd = ($_GET["battle"] * $bd);
    ?>

    <!---Total Attack--->
    <?php

    $tatt = ($tia + $tda + $tca + $tboa + $tba);
    ?>

    <!---Total Defence--->
    <?php
    $tdef = ($tid + $tdd + $tcd + $tbod + $tbd);
    ?>

       <!---Total Troops--->
    <?php
    $ttroops = ($_GET["inter"] + $_GET["destr"] + $_GET["cruiser"] + $_GET["bomb"] + $_GET["battle"] );
    ?>


    <table style="width:300px">
    <tr>
      <td>Troops</td>
      <td>Amount</td>       
      <td>Attack HP</td>
        <td>Defence HP</td>

    </tr>
    <tr>
      <td>Interceptors</td>
      <td><?php($_GET["inter"];)?></td>     
      <td><?php echo $tia;?></td>
    <td><?php echo $tid;?></td>

    </tr>
    <tr>
      <td>Destroyers</td>
      <td><?php($_GET["destr"];)?></td>     
      <td><?php echo $tda;?></td>
    <td><?php echo $tdd;?></td>

    </tr>
    <tr>
      <td>Cruisers</td>
      <td><?php($_GET["cruiser"];)?></td>       
      <td><?php echo $tca;?></td>
    <td><?php echo $tcd;?></td>

    </tr>
    <tr>
      <td>Bombers</td>
      <td><?php($_GET["bomb"];)?></td>      
      <td><?php echo $tboa;?></td>
    <td><?php echo $tbod;?></td>

    </tr>
    <tr>
      <td>Battleships</td>
      <td><?php($_GET["battle"];)?></td>        
      <td><?php echo $tba;?></td>
    <td><?php echo $tbd;?></td>

    </tr>

    <tr>
      <td>Totals</td>
      <td><?php echo $ttroops;?></td>       
      <td><?php echo $tatt;?></td>
    <td><?php echo $tdef;?></td>

    </tr>

    </table>

    <?php



    include "menu2.php";

    ?>
    </body>
    </html>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsio68964998 2014-08-23 12:03
    已采纳
    $ttroops = ($_GET["inter"] + $_GET["destr"] + $_GET["cruiser"] $_GET["bomb"] + $_GET["battle"] );
    

    Should be like

    $ttroops = ($_GET["inter"] + $_GET["destr"] + $_GET["cruiser"] + $_GET["bomb"] + $_GET["battle"] );
    

    As you forgot to add + between two $_GET variable..

    And I'm not sure.. Is it true line?
    $tatt - ($tia + $tda + $tca + $tboa + $tba);
    I think it should be
    $tatt = ($tia + $tda + $tca + $tboa + $tba);
    And
    <?php($_POST["inter"]);?> should be <?php echo $_POST["inter"]; ?>
    I've seen this mistake in multiple time in your code.

    打赏 评论
  • drgmszo076956 2014-08-23 11:45

    Please change the:

    <td><?php($_GET["Battle"];)?></td>
    

    to:

    <td><?php($_GET["battle"];)?></td>
    

    and the:

      <td><?php($_GET["Destr"];)?></td>
    

    to:

      <td><?php($_GET["destr"];)?></td>
    
    打赏 评论

相关推荐 更多相似问题