dtol41388 2018-11-29 04:53
浏览 24

如何防止表格出现

Link to code Since you cannot divide by 0, my php is to display an error message but, although it displays the error message it also displays the table that should appear if not dividing by 0. How can I prevent that?

        <!DOCTYPE html>
        <html>
        <head>
        <title>Math Calculations!</title>
        </head>
        <body>
        <!-- Background color selection for site-->
        <body style="background-color:#ACDDE3;">
        <?php

My values

        // input values
        $firstInt = $_POST["firstInt"];
        $secondInt = $_POST["secondInt"];
        $calc = $_POST["calc"];
        $result = 0;
        // inc-math-problems.php
        include ("juarez-inc-calc.php");

The statements

        elseif ($calc == "Multiplication") {
        $calculation = "Multiplication";
        $prefix = "The product of";
        $result = prodIntegers($firstInt, $secondInt);
        }
        elseif ($calc == "Divison") {
        $calculation = "Divison";
        $prefix = "The quotient of";

Target

        if ($secondInt == 0){
            print("Error: You can't divide by zero
            $result = "invalid";
        }
        else{
        $result = quotIntegers($firstInt, $secondInt);
        }

The print statements

        print("<style>
        table, th, td {
        border: 1px solid black;
        padding: 5px;
        }
        table {
        border-spacing: 5px;
        }
        </style>
        </head>
        <body>

        <h2>The Results</h2>

        <table>
        <tr>
        <th>Operation</th>
        <th>Result</th> 
        </tr>
        <tr>
        <td>$calculation</td>
        <td>$result</td>
        </tr>
        </table>");

        print("<a href=\"juarez-calculations.html\"> Return to form        </a>");

        ?>

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

2条回答 默认 最新

  • dsc80135 2018-11-29 05:02
    关注

    Try this:

    if ($secondInt == 0){
        print("Error: You cannot divide by zero");
        $result = "invalid";
    }
    else{
        $result = quotIntegers($firstInt, $secondInt);
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教