Home >Database >Mysql Tutorial >How to Fix the \'Trying to get property of non-object\' Error in CodeIgniter Form Elements?
Non-Object Property Error in CodeIgniter: Why and How to Fix It
When attempting to modify a form with specific data based on an ID, you may encounter the "Trying to get property of non-object" error in CodeIgniter. This occurs when attempting to access variables within the set_values() function of form elements.
The error arises when you try to use object notation ($product->prodname) to access elements within an array ($product). In PHP, arrays use array notation ($product['prodname']) to access their elements.
To address this issue, modify your code as follows:
<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>
The above is the detailed content of How to Fix the \'Trying to get property of non-object\' Error in CodeIgniter Form Elements?. For more information, please follow other related articles on the PHP Chinese website!