我想在表中插入多个族memeber datials,但错误有一些错误..
Notice: Undefined index: family_member_first_name_1 in C:\wamp64\www\finalproject\hrms(entigrity)\jobseek\index3.php on line 176
Notice: Undefined index: family_member_middle_name_1 in C:\wamp64\www\finalproject\hrms(entigrity)\jobseek\index3.php on line 177
和.......
Notice: Undefined index: family_member_nomination_ratio_1 in C:\wamp64\www\finalproject\hrms(entigrity)\jobseek\index3.php on line 186..
我有5个家庭成员扣留插入所以错误将来5次... 这里的代码是
<?php
include "config.php";
if(isset($_POST['family_member_btn'])) {
$family_member = $_POST['family_member'];
}
if(isset($_POST["submit4"])) {
if($_SESSION['email']) {
$db->where('primary_email',$_SESSION['email']);
$email_fetch_femily = $db->getone('om_user_list_a');
if($email_fetch_femily) {
$fetch_id_family = $email_fetch_femily['id'];
}
$cnt_row = $_POST["num"];
for($i=1; $i<=$cnt_row; $i++) {
$data5 = array(
"user_id" => $fetch_id_family,
"first_name" => $_POST['family_member_first_name_'.$i],
"middle_name" => $_POST['family_member_middle_name_'.$i],
"last_name" => $_POST['family_member_last_name_'.$i],
"birth_date" => $_POST['family_member_birth_date_'.$i],
"relative_type" => $_POST['family_member_relation_'.$i],
"marital_status" => $_POST['family_member_merital_status_'.$i],
"education_status" => $_POST['family_member_education_'.$i],
"occupation" => $_POST['family_member_occupation_'.$i],
"phone" => $_POST['family_member_phone_'.$i],
"gratuity_ratio" => $_POST['family_member_gratuity_ratio_'.$i],
"nomination_ratio" => $_POST['family_member_nomination_ratio_'.$i],
"status" => 1,
"created_by" => $fetch_id_family,
"created_date" => date('Y-m-d H:i:s'),
"created_ip" => $_SERVER['REMOTE_ADDR'],
);
$insert_family_details = $db->insert("om_relative_list",$data5);
if($insert_family_details) {
echo "<script>alert('family details insert successfully');</script>";
} else {
echo "<script>alert('!!!!family deatis insert unsuccessfully');</script>";
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<meta charset="utf-8"/>
<title>Pages - Admin Dashboard UI Kit - Form Wizard</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"/>
<link rel="apple-touch-icon" href="pages/ico/60.png">
<link rel="apple-touch-icon" sizes="76x76" href="pages/ico/76.png">
<link rel="apple-touch-icon" sizes="120x120" href="pages/ico/120.png">
<link rel="apple-touch-icon" sizes="152x152" href="pages/ico/152.png">
<link rel="icon" type="image/x-icon" href="favicon.ico"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta content="" name="description"/>
<meta content="" name="author"/>
<link href="assets/plugins/pace/pace-theme-flash.css" rel="stylesheet" type="text/css"/>
<link href="assets/plugins/bootstrapv3/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="assets/plugins/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css"/>
<link href="assets/plugins/jquery-scrollbar/jquery.scrollbar.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="assets/plugins/switchery/css/switchery.min.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="pages/css/pages-icons.css" rel="stylesheet" type="text/css" />
<link class="main-stylesheet" href="pages/css/pages.css" rel="stylesheet" type="text/css"/>
<!--[if lte IE 9]>
<link href="assets/plugins/codrops-dialogFx/dialog.ie.css" rel="stylesheet" type="text/css" media="screen" />
<![endif]-->
</head>
<body class="fixed-header ">
<div id="rootwizard" class="m-t-50">
<ul class="nav nav-tabs nav-tabs-linetriangle nav-tabs-separator nav-stack-sm">
<li class="">
<a data-toggle="tab" href="#tab4"><span>FAMILY DETAILS</span></a>
</li>
</ul>
<form method="post" action="" enctype="multipart/form-data">
<div class="tab-pane slide-left padding-20" id="tab4">
<div class="row row-same-height">
<div class="col-md-5 b-r b-dashed b-white ">
</div>
<div class="col-md-12">
<div class="padding-30" >
<div class="row clearfix">
<div class="col-sm-9">
<div class="form-group form-group-default">
<label><font size="2">HOW MANY MEMBER IN YOUR FAMILY ?</font></label>
<input type="text" name="family_member" class="form-control" />
</div>
</div>
<div class="col-sm-3">
<button type="submit" name="family_member_btn" class="btn btn-lg btn-info" style="padding:11pt;width:200px;"/><span><b><font size="2">SUBMIT</font></b></span></button>
</div>
</div><br><br>
<?php
for($i=1;$i<=$family_member;$i++) {
?>
<input type="hidden" value="<?php echo $family_member;?>" name="num" >
<div class="row clearfix">
<div class="col-sm-4">
<div class="form-group form-group-default">
<label><font size="2">First Name</font></label>
<input type="text" name="family_member_first_name[]" class="form-control" />
</div>
</div>
<div class="col-sm-4">
<div class="form-group form-group-default ">
<label><font size="2">Middle Name</font></label>
<input type="text" name="family_member_middle_name[]" class="form-control" >
</div>
</div>
<div class="col-sm-4">
<div class="form-group form-group-default ">
<label><font size="2">Last name</font></label>
<input type="text" name="family_member_last_name[]" class="form-control" />
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-4">
<div class="form-group form-group-default ">
<label><font size="2">birthdate</font></label>
<input id="datepicker3" class="form-control" name="family_member_birth_date[]" type="text" />
</div>
</div>
<div class="col-sm-4">
<div class="form-group form-group-default form-group-default-selectFx">
<label><font size="2">Realation</font></label>
<select class="cs-select cs-skin-slide cs-transparent form-control" name="family_member_relation[]" data-init-plugin="cs-select">
<option value=""></option>
<?php
$db->where('type_id','4');
$Industry=$db->get('om_master_values');
foreach($Industry as $indu){
?>
<option value="<?php echo $indu['id'] ?>" ><?php echo $indu['master_values'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-sm-4">
<div class="form-group form-group-default form-group-default-selectFx">
<label><font size="2">MARITAL STATUS</font></label>
<select class="cs-select cs-skin-slide cs-transparent form-control" name="family_member_merital_status[]" data-init-plugin="cs-select">
<option value=""></option>
<option value="married">MARRIED</option>
<option value="unmarried">UNMARRIED</option>
</select>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-4">
<div class="form-group form-group-default form-group-default-selectFx">
<label><font size="2">EDUCATION</font></label>
<select class="cs-select cs-skin-slide cs-transparent form-control" name="family_member_education[]" data-init-plugin="cs-select">
<option value=""></option>
<?php
$db->where('type_id','5');
$Industry=$db->get('om_master_values');
foreach($Industry as $indu){
?>
<option value="<?php echo $indu['id'] ?>" ><?php echo $indu['master_values'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-sm-4">
<div class="form-group form-group-default">
<label><font size="2">occupation</font></label>
<input type="text" name="family_member_occupation[]" class="form-control" />
</div>
</div>
<div class="col-sm-4">
<div class="form-group form-group-default">
<label><font size="2">PHONE</font></label>
<input type="text" name="family_member_phone[]" class="form-control" />
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-4">
<div class="form-group form-group-default">
<label><font size="2">gratuity_ratio</font></label>
<input type="text" name="family_member_gratuity_ratio[]" class="form-control" />
</div>
</div>
<div class="col-sm-4">
<div class="form-group form-group-default">
<label><font size="2">nomination_ratio</font></label>
<input type="text" name="family_member_nomination_ratio[]" class="form-control" />
</div>
</div>
</div>
<hr style="border:solid 2px rgba(0,0,0,0.2);">
<?php } ?>
</div><br><br>
<div class="padding-20">
<button class="btn btn-info btn-cons from-left pull-right" type="submit" name="submit4">
<span>SUBMIT</span>
</button>
</div>
</div>
</div>
</div>
<div class="tab-pane slide-left padding-20" id="tab5">
<div class="row row-same-height">
<div class="col-md-5 b-r b-dashed b-grey ">
<div class="padding-30 m-t-50">
</div>
</div>
</div>
</div>
<div class="tab-pane slide-left padding-20" id="tab6">
<div class="row row-same-height">
<div class="col-md-5 b-r b-dashed b-grey ">
</div>
</div>
</div>
<div class="tab-pane slide-left padding-20" id="tab7">
<div class="row row-same-height">
<div class="col-md-5 b-r b-dashed b-grey ">
</div>
</div>
</div>
</form>
</div>
</div>
<script src="assets/plugins/pace/pace.min.js" type="text/javascript"></script>
<script src="assets/plugins/jquery/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="assets/plugins/modernizr.custom.js" type="text/javascript"></script>
<script src="assets/plugins/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
<script src="assets/plugins/bootstrapv3/js/bootstrap.min.js" type="text/javascript"></script>
<script src="assets/plugins/jquery/jquery-easy.js" type="text/javascript"></script>
<script src="assets/plugins/jquery-unveil/jquery.unveil.min.js" type="text/javascript"></script>
<script src="assets/plugins/jquery-bez/jquery.bez.min.js"></script>
<script src="assets/plugins/jquery-ios-list/jquery.ioslist.min.js" type="text/javascript"></script>
<script src="assets/plugins/jquery-actual/jquery.actual.min.js"></script>
<script src="assets/plugins/jquery-scrollbar/jquery.scrollbar.min.js"></script>
<script type="text/javascript" src="assets/plugins/classie/classie.js"></script>
<script src="assets/plugins/switchery/js/switchery.min.js" type="text/javascript"></script>
<script src="assets/plugins/bootstrap3-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script type="text/javascript" src="assets/plugins/jquery-autonumeric/autoNumeric.js"></script>
<script type="text/javascript" src="assets/plugins/bootstrap-tag/bootstrap-tagsinput.min.js"></script>
<script type="text/javascript" src="assets/plugins/jquery-inputmask/jquery.inputmask.min.js"></script>
<script src="assets/plugins/bootstrap-form-wizard/js/jquery.bootstrap.wizard.min.js" type="text/javascript"></script>
<script src="assets/plugins/jquery-validation/js/jquery.validate.min.js" type="text/javascript"></script>
<script src="assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="assets/plugins/summernote/js/summernote.min.js" type="text/javascript"></script>
<script src="assets/plugins/moment/moment.min.js"></script>
<script src="assets/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>
<script src="assets/plugins/bootstrap-timepicker/bootstrap-timepicker.min.js"></script>
<script src="pages/js/pages.min.js"></script>
<script>
$(document).ready(function() {
$("#datepicker").datepicker();
});
</script>
<script>
$(document).ready(function() {
$("#datepicker2").datepicker();
});
</script>
<script>
$(document).ready(function() {
$("#datepicker3").datepicker();
});
</script>
<script src="assets/js/form_wizard.js" type="text/javascript"></script>
<script src="assets/js/scripts.js" type="text/javascript"></script>
<script src="assets/js/demo.js" type="text/javascript"></script>
<script>
window.intercomSettings = {
app_id: "xt5z6ibr"
};
</script>
</body>
</html>
答案 0 :(得分:2)
在您的html中,您正在使用数组:
<input type="text" name="family_member_first_name[]" class="form-control" />
^^ array in input name
所以在你的php中你需要使用数组来检查你的POST变量。
所以:
"first_name" => $_POST['family_member_first_name_'.$i],
// etc.
需要:
"first_name" => $_POST['family_member_first_name'][$i],
// etc.
编辑:您似乎正在使用POST变量来获取数组中的项目数。我还没有检查你是如何设置的,但最安全的选择是简单地计算其中一个数组中的项目数(这对复选框来说不会起作用......)。
您需要从0
开始,而不是1
。
所以改变:
for($i=1; $i<=$cnt_row; $i++) {
到:
for ($i = 0; $i < count($_POST['family_member_first_name']); $i++) {