dpevsxjn809817 2019-01-17 09:54
浏览 15
已采纳

无法在php中运行函数[关闭]

I'am not able to run a function in php oops concept. My data gets inserted without checking the validation code in check_data(). My form directly points to insert_payment_cash() function.

function check_data()
            {
                $error =0;
                $balance = ($_POST["pay_amount"])-($_POST["cash_amount"]);
                $invoice_id = $_POST["id"];
                if($_POST["cash_amount"]>$_POST["pay_amount"])
                {
                    $_SESSION['message'] = "Amount cannot be greater than pay amount<br>";
                    $error=1;
                }
                else if($balance == 0 && $_POST["penalty"] > 0)
                {
                    $_SESSION['message'] .= "If balance is zero(0), penalty will no be applied";
                    $error =1;
                }
                if($error == 1)
                {
                    header("location:../payment_details.php?id=$invoice_id");
                }
            }
            function insert_payment_cash()
            {
                $this->check_data();
                #rest insertion code 
    }
  • 写回答

1条回答 默认 最新

  • douguizhuang8276 2019-01-17 10:24
    关注

    session_start() function should be included in the beginning. Rest the code is same. It will work. and adding die after header()

    header("location:../payment_details.php?id=$invoice_id");
                die;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?