未定义的索引错误代码点火器


Undefined Index Error Codeigniter

我正在尝试编辑特定客户的详细信息。当我var_dump变量时,数据来自数据库并显示正确的数组结果,但它没有显示在文本字段中,并且存在未定义的索引错误。帮助我解决这个问题

这是我的控制器代码:

<?php
class Helpdesk extends CI_Controller {
public function __construct()
{
    parent::__construct();
    $this->load->model('crmstaff/helpdesk_model');
}
public function index()
{
if($this->session->userdata('isLogin') == FALSE)
{
  redirect('login ');
}else
{
  $this->load->model('crmstaff/m_login');
  $user = $this->session->userdata('username');
  $data['level'] = $this->session->userdata('level');        
  $data['user'] = $this->m_login->userData($user);
$this->load->helper('form');
$this->load->helper('url');
$data['customer'] = $this->helpdesk_model->get_pending_profile();
$data['title'] = 'Customer Details';
$this->load->view('website/crmstaff/general/header1', $data);
$this->load->view('website/crmstaff/helpdesk/index', $data);
$this->load->view('website/crmstaff/general/footer1', $data);
}
}
public function edit_permission($id=null) 
{   
if($this->session->userdata('isLogin') == FALSE)
{
  redirect('login ');
}else
{
  $this->load->model('crmstaff/m_login');
  $user = $this->session->userdata('username');
  $data['level'] = $this->session->userdata('level');        
  $data['user'] = $this->m_login->userData($user);
 $this->load->helper('form');
 $this->load->helper('url');
if($this->input->post('name'))
 {
    $data['customers'] = $this->helpdesk_model->edit_permission($this-  >input->post('id'));                
    //var_dump($data);
    if (empty($data['customers']))
    {
        show_404();
    }
//      redirect('tower/index');
    redirect('helpdesk/index', 'location', 301);
 }
 else
 {
     $data['customers']=$this->helpdesk_model->get_pending_profile($id);
     //print_r($data);
    // var_dump($data);
        //var_dump ($this->db->last_query());        
     $this->load->view('website/crmstaff/helpdesk/edit', $data);
 }
}
}
}
?>

型号代码:

<?php
class Helpdesk_model extends CI_Model {
public function __construct()
{
    $this->load->database();
}
public function get_custdetails($id = FALSE)
{
if ($id === FALSE)
{
    $query = $this->db->get('customers');
    return $query->result_array();
}
$query = $this->db->get_where('customers', array('customerId' => $id));
//  echo $this->db->last_query();
return $query->row_array();
}
public function get_pending_profile()
{
$query = $this->db->get('customers');
$where = "applicationStatus = 'SALES_CHECK_OK'";
$query = $this->db->get_where('customers', $where);
    return $query->result_array();
//  echo $this->db->last_query();
return $query->row_array();
}

public function edit_permission($id)
{
$data = array(
    'applicationStatus' => $this->input->post('status')
);
$this->db->where('customerId', $id);
$this->db->update('customers', $data); 
return $query = $this->db->get_where('customers', array('customerId' => $id))->row_array();
}
}
?>

在视图中:

<?php echo form_open('helpdesk/edit_permission');?>
<?php var_dump ($customers); ?>
<form method="get" class="form-horizontal">
 <div class="form-group"><label class="col-sm-2 control-label">Customer Name</label>                                    
 <div class="col-sm-10"><input type="text" class="form-control" name="name" value="<?php echo $customers['customerName']; ?>"></div>
                            </div>
                            <div class="form-group"><label class="col-sm-2 control-label">Address</label>
                                <div class="col-sm-10"><input type="text" class="form-control" name="add" value="<?php echo $customers['customerAddress']; ?>"></div>
                            </div>
                            <div class="form-group"><label class="col-sm-2 control-label">Email Address</label>
                                <div class="col-sm-10"><input type="text" class="form-control" name="payment" value="<?php echo $customers['email1']; ?>"></div>
                            </div>
                            <div class="form-group"><label class="col-sm-2 control-label">Application Status</label>
                                <div class="col-sm-10">
                                Activate: <input type="checkbox" value="SALES_CHECK_OK" name="status" />
                                </div>
                            </div>
                            <input type="hidden" value="<?php echo $customers['customerId']; ?>" name="id" />
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-white" type="submit">Cancel</button>
                                    <button class="btn btn-primary" type="submit">Update</button>
                                </div>
                            </div>
                        </form>

在视图中,我得到了错误

遇到 PHP 错误

Severity: Notice
Message: Undefined index: customerName
Filename: helpdesk/edit.php
Line Number: 114

var_dump($customers)的输出;

array(1) {
 [0]=>
 array(37) {
["customerId"]=>
string(1) "5"
["customerName"]=>
string(7) "Geetika"
["customerDOB"]=>
string(10) "0000-00-00"
["house"]=>
string(0) ""
["customerProfession"]=>
string(0) ""
["previousISP"]=>
string(1) "0"
["customerPaymentDetails"]=>
NULL
["chqNo"]=>
string(1) "0"
["bankName"]=>
string(0) ""
["date"]=>
string(10) "0000-00-00"
["amount"]=>
string(1) "0"
["customerAddress"]=>
string(15) "ambamata scheme"
["city"]=>
string(0) ""
["state"]=>
string(0) ""
["pin"]=>
string(1) "0"
["phnoRes"]=>
string(1) "0"
["phnoOffice"]=>
string(1) "0"
["phnoMobile"]=>
string(1) "0"
["billAddress"]=>
string(0) ""
["billCity"]=>
string(0) ""
["billState"]=>
string(0) ""
["billPin"]=>
string(1) "0"
["billPhnoRes"]=>
string(1) "0"
["billPhnoOffice"]=>
string(1) "0"
["billPhnoMobile"]=>
string(1) "0"
["idProof"]=>
string(0) ""
["email1"]=>
string(20) "gitikajsh619@gmail.c"
["email2"]=>
string(0) ""
["hardware"]=>
string(0) ""
["staticIP"]=>
string(1) "0"
["applicationStatus"]=>
string(14) "SALES_CHECK_OK"
["planType"]=>
string(6) "1month"
["planDuration"]=>
string(0) ""
["wirelessRouter"]=>
string(0) ""
["macIDOFCPE"]=>
NULL
["TowerID"]=>
NULL
["message"]=>
string(14) "new connection"
 }

您从数据库中获得了单行数据,该数组在第 0 个索引处有数据,因此请在视图中使用以下代码

<?php echo $customers[0]['customerName']; ?>

你实际上是在处理数组数组。

array(1) {
    array(37) {
        ["customerId"]=>
        string(1) "5"

这给了我这样的解释:

$customers["customerName"]

未定义,因为 customerName$customers 中第 0 个数组的属性。

$customers[0]["customerName"]

这应该给你你想要的东西。

如果您的数组转储更像,那么您是对的

array(1) {
    ["customerId"]=>
    string(1) "5"

我建议使用 isset 来检查您的变量是否实际设置。