Home >Database >Mysql Tutorial >How to Fix \'Trying to get property of non-object\' Error in CodeIgniter Edit Form?
When attempting to edit records in CodeIgniter, you may encounter the "Trying to get property of non-object" error when populating your edit form. This error indicates that the $product variable used to retrieve data is not an object.
To resolve this issue, use array notation to access the array elements rather than object notation. Instead of $product->prodname, use $product['prodname'].
In your edit_product_view.php file, update the following:
<code class="php"><td><?php echo form_label('Name:'); ?></td> <td><?php echo form_input('prodname', set_value('prodname', $product['prodname'])); ?></td> <td><?php echo form_label('Product Type:'); ?></td> <td><?php echo form_dropdown('ptname_fk', $product_types, set_value('ptname_fk', $product['ptname_fk'])); ?></td></code>
Array notation accesses the elements directly from the array, resolving the "Trying to get property of non-object" error. Your edit form will now correctly populate with the data retrieved from the database.
The above is the detailed content of How to Fix \'Trying to get property of non-object\' Error in CodeIgniter Edit Form?. For more information, please follow other related articles on the PHP Chinese website!