如何修复此错误“通知:未定义的偏移量”并将记录保存到数据库?

时间:2015-09-28 21:17:23

标签: php web undefined offset

我正在研究费用管理系统并收到错误“通知:未定义的偏移量”

Notice: Undefined offset: 32 in H:\USB-Server\root\include\PayFee.php on line 14
Notice: Undefined offset: 1 in H:\USB-Server\root\include\PayFee.php on line 17
Notice: Undefined index: 7-H in H:\USB-Server\root\include\PayFee.php on line 20
Notice: Undefined offset: 0 in H:\USB-Server\root\include\PayFee.php on line 23
Notice: Undefined index: 2015-09-02 in H:\USB-Server\root\include\PayFee.php on line 26
Notice: Undefined index: Cash in H:\USB-Server\root\include\PayFee.php on line 29
Notice: Undefined index: dffd in H:\USB-Server\root\include\PayFee.php on line 32
Notice: Undefined index: 2015-09-23 in H:\USB-Server\root\include\PayFee.php on line 35
Notice: Undefined offset: 1000 in H:\USB-Server\root\include\PayFee.php on line 38
Notice: Undefined variable: fee_concession in H:\USB-Server\root\include\PayFee.php on line 41
Notice: Undefined index: in H:\USB-Server\root\include\PayFee.php on line 41
Notice: Undefined offset: 0 in H:\USB-Server\root\include\PayFee.php on line 44
Notice: Undefined offset: 0 in H:\USB-Server\root\include\PayFee.php on line 47
Notice: Undefined offset: 0 in H:\USB-Server\root\include\PayFee.php on line 50
Notice: Undefined offset: 1000 in H:\USB-Server\root\include\PayFee.php on line 53

而且每当我试图在数据库中保存记录时,它都会保存,如下图所示

enter image description here

我正在使用以下代码: -

if(isset($_REQUEST['submit']))
{
$errorMessage = "";
$s_student_id = mysql_real_escape_string($_POST['studentID']);
$student_id = $_POST[$s_student_id];
$s_school_id = mysql_real_escape_string($_POST['schoolID']);
$school_id = $_POST[$s_school_id];
$s_fee_classsec = mysql_real_escape_string($_POST['classID']);
$fee_classsec = $_POST[$s_fee_classsec];
$s_fee_status = mysql_real_escape_string($_POST['feeStatus']);
$fee_status = $_POST[$s_fee_status];
$s_fee_dueDate = mysql_real_escape_string($_POST['fee_dueDate']);
$fee_dueDate = $_POST[$s_fee_dueDate];
$s_fee_mode = mysql_real_escape_string($_POST['fee_mode']);
$fee_mode = $_POST[$s_fee_mode];
$s_fee_info = mysql_real_escape_string($_POST['fee_info']);
$fee_info = $_POST[$s_fee_info];
$s_fee_paidDate = mysql_real_escape_string($_POST['fee_paidDate']);
$fee_paidDate = $_POST[$s_fee_paidDate];
$s_fee_amount = mysql_real_escape_string($_POST['fee_amount']);
$fee_amount = $_POST[$s_fee_amount];
$s_fee_concession = mysql_real_escape_string($_POST['fee_concession']);
$fee_concession = $_POST[$fee_concession];
$s_fee_lateCharges = mysql_real_escape_string($_POST['fee_lateCharges']);
$fee_lateCharges = $_POST[$s_fee_lateCharges];
$s_fee_vat = mysql_real_escape_string($_POST['fee_vat']);
$fee_vat = $_POST[$s_fee_vat];
$s_fee_serviceTax = mysql_real_escape_string($_POST['fee_serviceTax']);
$fee_serviceTax = $_POST[$s_fee_serviceTax];
$s_fee_grandTotal = mysql_real_escape_string($_POST['fee_grandTotal']);
$fee_grandTotal = $_POST[$s_fee_grandTotal];
$insqDbtb = "INSERT INTO fee_info (
student_id, 
school_id, 
fee_status, 
fee_classsec, 
fee_due_date, 
fee_paid_date, 
fee_amount, 
fee_late_charges, 
fee_concession, 
fee_vat, 
fee_service_tax, 
fee_total, 
fee_mode, 
fee_info) 
VALUES ('$student_id',
'$school_id',
'$fee_classsec',
'$fee_status',
'$fee_dueDate',
'$fee_paidDate',
'$fee_amount',
'$fee_lateCharges',
'$fee_concession',
'$fee_vat',
'$fee_serviceTax',
'$fee_grandTotal',
'$fee_mode',
'$fee_info')";
mysqli_query($link,$insqDbtb) or die(mysqli_error($link));
echo 'Record saved...';
}

任何人都可以帮我解决这个问题吗?我没有意识到这个问题:(

1 个答案:

答案 0 :(得分:0)

$_POST是一个包含HTTP请求中发布的数据的数组。

你有这个:

$s_student_id = mysql_real_escape_string($_POST['studentID']);
$student_id = $_POST[$s_student_id];

应该是这样的:

$student_id = mysql_real_escape_string($_POST['studentID']);

有关处理来自beginner friendly tutorial的表单提交的详细信息。