0

I am trying to edit a specific customer's details. The data is arriving from database and displaying the correct array result when i var_dump the variable, but its not showing in the text field and an undefined index error is there. Help me out in solving this

This is my controller code:

<?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);
 }
}
}
}
?>

Model Code:

<?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();
}
}

?>

in View:

<?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>

in the view i an getting the error

A PHP Error was encountered

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

Output of 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"
 }
CSchulz
  • 10,882
  • 11
  • 60
  • 114
Geetika Joshi
  • 27
  • 2
  • 9

2 Answers2

0

You're really working with an array of arrays.

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

This gives me the interpretation that

$customers["customerName"]

is not defined because customerName is a property of the 0th array within $customers.

$customers[0]["customerName"]

This should give you what you're looking for.

You'd be right if your array dump would be more like

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

I recommend using isset to check whether your variables are actually set or not.

Community
  • 1
  • 1
Jonast92
  • 4,964
  • 1
  • 18
  • 32
0

You got single row of data from database the array have data at 0th index so use below code in your view

<?php echo $customers[0]['customerName']; ?>
codex
  • 446
  • 1
  • 7
  • 17