Php 未定义偏移量:2英寸编码器点火器
这是我的控制器功能,据我所知,没有错误,但它仍然向我显示这条消息。这是什么意思Php 未定义偏移量:2英寸编码器点火器,php,codeigniter,Php,Codeigniter,这是我的控制器功能,据我所知,没有错误,但它仍然向我显示这条消息。这是什么意思 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class User extends CI_Controller { public function __construct() { parent::__construct(); //
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class User extends CI_Controller { public function __construct() { parent::__construct(); // Your own constructor code //$this->load->model('user_model'); } public function index() { $this->load->view('user/signup'); } public function registration() { if($this->input->post()) { $fullname=$this->input->post('fullname'); $fullnameSplit= explode(" ", $fullname); $reg_data = array( 'membershipid'=>"Ls-".rand(), 'role'=>1, 'firstname'=>$fullnameSplit[0], 'middlename'=>$fullnameSplit[1], 'lastname'=>$fullnameSplit[2], 'Company_name'=>$this->input->post('companyname'), 'email'=>$this->input->post('email'), 'password'=>sha1($this->input->post('password')), ); print_r($reg_data); //$this->user_model->register_user($reg_data); //redirect('user/login'); //echo '<pre>'; print_r($reg_data); die; }else { //$data['current_page'] = 'Register'; //$this->load->view('registration',$data); } } }
使用这一行 作为
错误undefined OFET:2表示键为[2]的数组$fullnameSplit不存在或未设置。因此,您需要检查条件isset()以避免出现这样的消息用户控制器中的php标记上方是否有空格?如果是,请删除不需要的空格,也只需注释print\r($reg\u data)代码>不依赖于用户输入。始终制作虚拟验证代码。最好的方法应该是有更多的输入字段,即
,$f_name
,$m_name
,并且在控制器中检查这些字段是否为空,然后再使用它们。 A PHP Error was encountered Severity: Notice Message: Undefined offset: 2 Filename: controllers/User.php Line Number: 35 Backtrace: File: /var/www/overtribe.com/public_html/listspread/application/controllers/User.php Line: 35 Function: _error_handler File: /var/www/overtribe.com/public_html/listspread/index.php Line: 293 Function: require_once$l_name
'lastname'=>$fullnameSplit[2],
'lastname'=>isset($fullnameSplit[2]) ? $fullnameSplit[2] : '',