Trying to get property of non-object - CodeIgniter
To access the elements in the array, use array notation: $product['prodname']
$product->prodname
is object notation, which can only be used to access object attributes and methods.
Code Igniter - Trying to get property of a non object
Hope this will help you :
Since u r using single item with object in your controller,So you should use row()
instead of result_array()
;
Your model should be like this :
public function get($id)
{
$results = $this->db->get_where('products', array('pro_id' => $id));
return $results->row();
}
Your controller should be like this :
Print $data
in your controller to check it has data;
public function add()
{
$id = $this->input->post('id');
$product = $this->products_model->get($id);
$data = array(
'id' => $id,
'name' => $product->pro_name,
'qty' => 1,
'price' => $product->pro_price
);
print_r($data); die();
$this->cart->insert($data);
}
For more : https://www.codeigniter.com/user_guide/database/results.html
How to solve Message: Trying to get property of non-object error in Codeigniter?
do like this
$get_bank = $this->FD_Model->get_bank_by_branch($branch_list[0]->bankid);
AND
'br_bank' => $get_bank[0]->bank_name # this will work maybe
or
'br_bank' => $get_bank[0]['bank_name']
Its
0
indexed array so you need to add the key to access the child's
Trying to get property of non-object using codeigniter
change this in your model $rows = $query->result_array();
and also use if(isset){}
to check for empty
Severity: Notice Trying to get property of non-object and did not get any data from database table codeigniter
I did not get product_id.I forgot to name the 'product_id' in my view page.When i placed the name='product_id' in view page, this actually solved the problem.
Related Topics
Whats the Easiest Way to Determine If a User Is Online? (Php/Mysql)
How to Return a Proper Success/Error Message for Jquery .Ajax() Using PHP
How to Remove the Leading Character from a String
Fastest Hash for Non-Cryptographic Uses
Check to See If a String Is Serialized
Accessing Laravel .Env Variables in Blade
PHP Composer Update "Cannot Allocate Memory" Error (Using Laravel 4)
What Is Normalized Utf-8 All About
How to Query All the Graphql Type Fields Without Writing a Long Query
Reconnection of Client When Server Reboots in Websocket
How to Password-Protect PHP Page
Round to Max Thousand, Hundred etc in PHP
Get Coupon Data from Woocommerce Orders