Home > Database > Mysql Tutorial > ## Why am I Getting the \'Trying to Get Property of Non-Object\' Error in CodeIgniter?

## Why am I Getting the \'Trying to Get Property of Non-Object\' Error in CodeIgniter?

Linda Hamilton
Release: 2024-10-25 06:56:02
Original
879 people have browsed it

## Why am I Getting the

Troubleshooting "Trying to Get Property of Non-Object" Error in CodeIgniter

In CodeIgniter, when attempting to update a form with retrieved data for a specific ID, it's possible to encounter the error "Trying to get property of non-object." This issue generally arises due to incorrect usage of object or array notation when accessing retrieved data.

To resolve this error, it's crucial to use the array notation, $product['property'], when accessing array elements. In your provided code excerpt, you're attempting to access array elements using object notation, $product->property, which is applicable for object attributes and methods only.

Here's a corrected version of your edit_product_view:

<?php echo form_input('prodname', set_value('prodname', $product['prodname'])); ?>
Copy after login
<?php echo form_dropdown('ptname_fk', $product_types, set_value('ptname_fk', $product['ptname_fk'])); ?>
Copy after login

By utilizing array notation, your form will correctly populate with the retrieved data for the selected product.

The above is the detailed content of ## Why am I Getting the \'Trying to Get Property of Non-Object\' Error in CodeIgniter?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template