Home  >  Article  >  Database  >  ## 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
Linda HamiltonOriginal
2024-10-25 06:56:02775browse

## 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'])); ?>
<?php echo form_dropdown('ptname_fk', $product_types, set_value('ptname_fk', $product['ptname_fk'])); ?>

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!

Statement:
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