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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改