无法在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
}
答
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;