我正在使用Codigniter,我在发布表单数据方面存在问题。 在我的形式,有不同的部分,我已经为不同的部分放置数组
这是我的代码(控制器)
<?php
class Resume extends CI_Controller{
var $user_id;
function __construct(){
parent::__construct();
$this->user_id = $this->session->userdata('user_id');
$this->load->model("Resume_model");
if($this->session->userdata('user_id') == NULL){
redirect('user/login','refresh');
}
}
public function index(){
$this->Resume();
}
public function Resume(){
if($this->input->post('Skills')){
$Resume = $this->input->post();
$ResumeInsert=array();
$ResumeUpdate=array();
$Key_Resume__ExistIDs=array();
foreach($this->input->post('Person_id') as $key =>$value ){
$ResumeInsert[$key]['updated'] = Date("Y-m-d");
$ResumeInsert[$key]['Importance_JK'] = $Resume['Importance_JK'];
$ResumeInsert[$key]['user_FK'] = $user_id;
$ResumeInsert[$key]['Person_id'] = $Resume['Person_id'][$key];
$ResumeInsert[$key]['email_contact'] = $Resume['email_contact'][$key];
$ResumeInsert[$key]['Contact_Phone'] = $Resume['Contact_Phone'][$key];
$ResumeInsert[$key]['communication'] = $Resume['communication'][$key];
$ResumeInsert[$key]['creativity'] = $Resume['creativity'][$key];
$ResumeInsert[$key]['team_work'] = $Resume['team_work'][$key];
$ResumeInsert[$key]['organizational'] = $Resume['organizational'][$key];
$ResumeInsert[$key]['Leadership'] = $Resume['Leadership'][$key];
$ResumeInsert[$key]['Productivity'] = $Resume['Productivity'][$key];
$ResumeInsert[$key]['Postal_Address'] = $Resume['Postal_Address'][$key];
$ResumeInsert[$key]['Career_objective'] = $Resume['Career_objective'][$key];
}
foreach($this->input->post('emp_id') as $key =>$value ){
$ResumeInsert[$key]['resume_keyid'] = $Resume['emp_id'][$key];
$ResumeInsert[$key]['employer_name'] = $Resume['employer_name'][$key];
$ResumeInsert[$key]['start_Date'] = $Resume['start_Date'][$key];
$ResumeInsert[$key]['end_date'] = $Resume['end_date'][$key];
$ResumeInsert[$key]['type_id'] = $Resume['type_id'][$key];
$ResumeInsert[$key]['position'] = $Resume['position'][$key];
$ResumeInsert[$key]['responsibility'] = $Resume['responsibility'][$key];
$ResumeInsert[$key]['Skills'] = $Resume['Skills'][$key];
print_r ($ResumeInsert);exit;
}
foreach($this->input->post('resume_id1') as $key =>$value ){
$ResumeInsert[$key]['edu_id'] = $Resume['resume_id1'][$key];
$ResumeInsert[$key]['year_gain'] = $Resume['year_gain'][$key];
$ResumeInsert[$key]['qualification_name'] = $Resume['qualification_name'][$key];
$ResumeInsert[$key]['institution_name'] = $Resume['institution_name'][$key];
$ResumeInsert[$key]['outstanding_Ach'] = $Resume['outstanding_Ach'][$key];
$ResumeInsert[$key]['aquired_skill'] = $Resume['aquired_skill'][$key];
$ResumeInsert[$key]['expiry'] = $Resume['expiry'][$key];
$ResumeInsert[$key]['Application_of_Skill'] = $Resume['Application_of_Skill'][$key];
}
foreach($this->input->post('resume_id2') as $key =>$value ){
$ResumeInsert[$key]['resume_skillID'] = $Resume['resume_id2'][$key];
$ResumeInsert[$key]['skill_name'] = $Resume['skill_name'][$key];
$ResumeInsert[$key]['Licences_permits'] = $Resume['Licences_permits'][$key];
$ResumeInsert[$key]['date_Achived'] = $Resume['date_Achived'][$key];
$ResumeInsert[$key]['expiry_renewal'] = $Resume['expiry'][$key];
$ResumeInsert[$key]['skill_work'] = $Resume['application_of_skill'][$key];
$ResumeInsert[$key]['course_tilte'] = $Resume['course_tilte'][$key];
}
foreach($this->input->post('resume_id3') as $key =>$value ){
$ResumeInsert[$key]['hobbyId'] = $Resume['resume_id3'][$key];
$ResumeInsert[$key]['hobby_name'] = $Resume['hobby_name'][$key];
$ResumeInsert[$key]['achievement_name'] = $Resume['achievement_name'][$key];
$ResumeInsert[$key]['Application_OF_hobby_work'] = $Resume['Application_of_Skill'][$key];
}
foreach($this->input->post('resume_id4') as $key =>$value ){
$ResumeInsert[$key]['ref_resume_ID'] = $Resume['resume_id4'][$key];
$ResumeInsert[$key]['referee_name'] = $Resume['referee_name'][$key];
$ResumeInsert[$key]['Position_referee'] = $Resume['Position'][$key];
$ResumeInsert[$key]['company_name_ref'] = $Resume['company_name'][$key];
$ResumeInsert[$key]['phone_ref'] = $Resume['phone_ref'][$key];
$ResumeInsert[$key]['contact_email_ref'] = $Resume['contact_email'][$key];
$ResumeInsert[$key]['reference_Type'] = $Resume['reference_Type'][$key];
$ResumeInsert[$key]['Application_of_Skill_ref'] = $Resume['Application_of_Skill'][$key];
}
foreach($this->input->post('resume_id5') as $key =>$value ){
$ResumeInsert[$key]['Application_Id'] = $Resume['resume_id5'][$key];
$ResumeInsert[$key]['app_date_sent'] = $Resume['date_sent'][$key];
$ResumeInsert[$key]['app_busisness_name'] = $Resume['app_busisness_name'][$key];
$ResumeInsert[$key]['app_address'] = $Resume['app_address'][$key];
$ResumeInsert[$key]['app_contact_phone'] = $Resume['app_contact_phone'][$key];
$ResumeInsert[$key]['app_outcome'] = $Resume['app_outcome'][$key];
$ResumeInsert[$key]['app_date_closed'] = $Resume['app_date_closed'][$key];
}
if(isset($Resume['id'][$key]))
{
// echo "test";exit;
$Key_Resume__ExistIDs[]=$Resume['id'][$key];
if( $ResumeInsert[$key]['Person_id'] != ""){
$ResumeUpdate[$key]['Person_id'] = $ResumeInsert[$key]['Person_id'];
}
if( $ResumeInsert[$key]['email_contact'] != ""){
$ResumeUpdate[$key]['email_contact'] = $ResumeInsert[$key]['email_contact'];
}
if( $ResumeInsert[$key]['Contact_Phone'] != ""){
$ResumeUpdate[$key]['Contact_Phone'] = $ResumeInsert[$key]['Contact_Phone'];
}
if( $ResumeInsert[$key]['communication'] != ""){
$ResumeUpdate[$key]['communication'] = $ResumeInsert[$key]['communication'];
}
if( $ResumeInsert[$key]['creativity'] != ""){
$ResumeUpdate[$key]['creativity'] = $ResumeInsert[$key]['creativity'];
}
if( $ResumeInsert[$key]['team_work'] != ""){
$ResumeUpdate[$key]['team_work'] = $ResumeInsert[$key]['team_work'];
}
if( $ResumeInsert[$key]['organizational'] != ""){
$ResumeUpdate[$key]['organizational'] = $ResumeInsert[$key]['organizational'];
}
if( $ResumeInsert[$key]['Leadership'] != ""){
$ResumeUpdate[$key]['Leadership'] = $ResumeInsert[$key]['Leadership'];
}
if( $ResumeInsert[$key]['Productivity'] != ""){
$ResumeUpdate[$key]['Productivity'] = $ResumeInsert[$key]['Productivity'];
}
if( $ResumeInsert[$key]['Postal_Address'] != ""){
$ResumeUpdate[$key]['Postal_Address'] = $ResumeInsert[$key]['Postal_Address'];
}
if( $ResumeInsert[$key]['Career_objective'] != ""){
$ResumeUpdate[$key]['Career_objective'] = $ResumeInsert[$key]['Career_objective'];
}
if( $ResumeInsert[$key]['resume_keyid'] != ""){
$ResumeUpdate[$key]['resume_keyid'] = $ResumeInsert[$key]['resume_keyid'];
}
if( $ResumeInsert[$key]['employer_name'] != ""){
$ResumeUpdate[$key]['employer_name'] = $ResumeInsert[$key]['employer_name'];
}
if( $ResumeInsert[$key]['start_Date'] != ""){
$ResumeUpdate[$key]['start_Date'] = $ResumeInsert[$key]['start_Date'];
}
if( $ResumeInsert[$key]['end_date'] != "") {
$ResumeUpdate[$key]['end_date'] = $ResumeInsert[$key]['end_date'];
}
if( $ResumeInsert[$key]['type_id'] != ""){
$ResumeUpdate[$key]['type_id'] = $ResumeInsert[$key]['type_id'];
}
if( $ResumeInsert[$key]['position'] != ""){
$ResumeUpdate[$key]['position'] = $ResumeInsert[$key]['position'];
}
if( $ResumeInsert[$key]['edu_id'] != ""){
$ResumeUpdate[$key]['edu_id'] = $ResumeInsert[$key]['edu_id'];
}
if( $ResumeInsert[$key]['year_gain'] != ""){
$ResumeUpdate[$key]['year_gain'] = $ResumeInsert[$key]['year_gain'];
}
if( $ResumeInsert[$key]['qualification_name'] != ""){
$ResumeUpdate[$key]['qualification_name'] = $ResumeInsert[$key]['qualification_name'];
}
if( $ResumeInsert[$key]['institution_name'] != ""){
$ResumeUpdate[$key]['institution_name'] = $ResumeInsert[$key]['institution_name'];
}
if( $ResumeInsert[$key]['outstanding_Ach'] != ""){
$ResumeUpdate[$key]['outstanding_Ach']= $ResumeInsert[$key]['outstanding_Ach'];
}
if( $ResumeInsert[$key]['aquired_skill'] != ""){
$ResumeUpdate[$key]['aquired_skill'] = $ResumeInsert[$key]['aquired_skill'];
}
if( $ResumeInsert[$key]['expiry'] != ""){
$ResumeUpdate[$key]['expiry'] = $ResumeInsert[$key]['expiry'];
}
if( $ResumeInsert[$key]['Application_of_Skill'] != ""){
$ResumeUpdate[$key]['Application_of_Skill'] = $ResumeInsert[$key]['Application_of_Skill'];
}
if( $ResumeInsert[$key]['resume_skillID'] != ""){
$ResumeUpdate[$key]['resume_skillID'] = $ResumeInsert[$key]['resume_skillID'];
}
if( $ResumeInsert[$key]['skill_name'] != ""){
$ResumeUpdate[$key]['skill_name'] = $ResumeInsert[$key]['skill_name'];
}
if( $ResumeInsert[$key]['Licences_permits'] != ""){
$ResumeUpdate[$key]['Licences_permits'] = $ResumeInsert[$key]['Licences_permits'];
}
if( $ResumeInsert[$key]['date_Achived'] != ""){
$ResumeUpdate[$key]['date_Achived'] = $ResumeInsert[$key]['date_Achived'];
}
if( $ResumeInsert[$key]['expiry_renewal'] !="") {
$ResumeUpdate[$key]['expiry_renewal'] = $ResumeInsert[$key]['expiry_renewal'];
}
if( $ResumeInsert[$key]['skill_work'] != ""){
$ResumeUpdate[$key]['skill_work'] = $ResumeInsert[$key]['skill_work'];
}
if( $ResumeInsert[$key]['course_tilte'] != ""){
$ResumeUpdate[$key]['course_tilte'] = $ResumeInsert[$key]['course_tilte'];
}
if( $ResumeInsert[$key]['hobbyId'] != ""){
$ResumeUpdate[$key]['hobbyId'] = $ResumeInsert[$key]['hobbyId'];
}
if( $ResumeInsert[$key]['hobby_name'] != ""){
$ResumeUpdate[$key]['hobby_name'] = $ResumeInsert[$key]['hobby_name'];
}
if( $ResumeInsert[$key]['achievement_name'] != ""){
$ResumeUpdate[$key]['achievement_name'] = $ResumeInsert[$key]['achievement_name'];
}
if( $ResumeInsert[$key]['Application_OF_hobby_work'] != ""){
$ResumeUpdate[$key]['Application_OF_hobby_work'] = $ResumeInsert[$key]['Application_OF_hobby_work'];
}
if( $ResumeInsert[$key]['ref_resume_ID'] != ""){
$ResumeUpdate[$key]['ref_resume_ID'] = $ResumeInsert[$key]['ref_resume_ID'];
}
if( $ResumeInsert[$key]['referee_name'] != ""){
$ResumeUpdate[$key]['referee_name'] = $ResumeInsert[$key]['referee_name'];
}
if( $ResumeInsert[$key]['Position_referee'] != ""){
$ResumeUpdate[$key]['Position_referee'] = $ResumeInsert[$key]['Position_referee'];
}
if( $ResumeInsert[$key]['company_name_ref'] != ""){
$ResumeUpdate[$key]['company_name_ref'] = $ResumeInsert[$key]['company_name_ref'];
}
if( $ResumeInsert[$key]['phone_ref'] != ""){
$ResumeUpdate[$key]['phone_ref'] = $ResumeInsert[$key]['phone_ref'];
}
if( $ResumeInsert[$key]['contact_email_ref'] != ""){
$ResumeUpdate[$key]['contact_email_ref'] = $ResumeInsert[$key]['contact_email_ref'];
}
if( $ResumeInsert[$key]['reference_Type'] != ""){
$ResumeUpdate[$key]['reference_Type'] = $ResumeInsert[$key]['reference_Type'];
}
if( $ResumeInsert[$key]['Application_of_Skill_ref'] != ""){
$ResumeUpdate[$key]['Application_of_Skill_ref'] = $ResumeInsert[$key]['Application_of_Skill_ref'];
}
if( $ResumeInsert[$key]['app_date_sent'] != ""){
$ResumeUpdate[$key]['app_date_sent'] = $ResumeInsert[$key]['app_date_sent'];
}
if( $ResumeInsert[$key]['Application_Id'] != ""){
$ResumeUpdate[$key]['Application_Id'] = $ResumeInsert[$key]['Application_Id'];
}
if( $ResumeInsert[$key]['app_busisness_name'] != ""){
$ResumeUpdate[$key]['app_busisness_name'] = $ResumeInsert[$key]['app_busisness_name'];
}
if( $ResumeInsert[$key]['app_address'] != ""){
$ResumeUpdate[$key]['app_address'] = $ResumeInsert[$key]['app_address'];
}
if( $ResumeInsert[$key]['app_contact_phone'] != "")
{
$ResumeUpdate[$key]['app_contact_phone'] = $ResumeInsert[$key]['app_contact_phone'];
}
if( $ResumeInsert[$key]['app_outcome'] != ""){
$ResumeUpdate[$key]['app_outcome'] = $ResumeInsert[$key]['app_outcome'];
}
if( $ResumeInsert[$key]['app_date_closed'] != ""){
$ResumeUpdate[$key]['app_date_closed'] = $ResumeInsert[$key]['app_date_closed'];
}
if( $ResumeInsert[$key]['resume_id'] != ""){
$ResumeUpdate[$key]['resume_id'] = $ResumeInsert[$key]['resume_id'];
}
$ResumeUpdate[$key]['resume_id']=$Resume['id'][$key];
unset($ResumeInsert[$key]);
}
else{
$ResumeInsert[$key]['resume_id'] = $GetLastID;
$GetLastID++;
}
$status=$this->Resume_model->ProcessData($idsToDelete,$ResumeUpdate,$user_id,$ResumeInsert,$imgInsert,$imgUpdate);
redirect('Resume','refresh');
}
}
?>
此处为插入查询(模型)
function ProcessData($tbl_resumeInsert){
if(!empty($tbl_resumeInsert))
{
$this->insert_tbl_resume($user_id,$tbl_resumeInsert);
}
}
function insert_tbl_resume($id,$arrtbl_resume)
{
$this->db->insert_batch('tbl_resume', $arrtbl_resume);
}
在上面的代码中,当我要提交表单时,只有 Foreach loop
的数据可以插入,当我打印 $ResumeInsert
,它只显示第一个foreach循环数据foreach($this->input->post('Person_id') as $key =>$value )
其余的foreach循环数据在 DB
NULL
请帮忙吗? 谢谢!
答案 0 :(得分:0)
函数$this->input->post('something')
从$_POST
数组中返回一个值为&#39;&#39;的键。如果关键的话“&#39;不存在它返回NULL。 (或CI版本中的FALSE&lt; 3.0)
$_POST
是一个关联数组,最多只有一个具有任何给定键的项。所以代码
foreach($this->input->post('Person_id') as $key =>$value )
{
...
只会运行一次,因为只有一个$_POST
数组项,其中包含键&#39; Person_id&#39;。
如果您的表单html有多个名为&#39; Person_id&#39;只有最后一个字段的值才会发布到服务器。