Home >Database >Mysql Tutorial >How to Fix the \'Trying to Get Property of Non-Object\' Error in CodeIgniter Update Forms?
When attempting to populate an update form in CodeIgniter, you may encounter the dreaded "Trying to get property of non-object" error. This issue arises when you try to access non-existent properties within an object.
To resolve this error, you need to ensure that you are using the correct notation to retrieve values from your data array. CodeIgniter allows you to access array elements in two ways:
In your case, the issue lies in your set_values() calls. You are incorrectly using object notation (e.g., $product->prodname) instead of array notation (e.g., $product['prodname']).
Corrected Code:
<code class="php"><?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'])); ?></code>
Remember, array notation uses square brackets, while object notation uses the arrow symbol. By using array notation, you are directly accessing the elements within the $product array rather than trying to retrieve attributes of a non-existent object.
The above is the detailed content of How to Fix the \'Trying to Get Property of Non-Object\' Error in CodeIgniter Update Forms?. For more information, please follow other related articles on the PHP Chinese website!