Home > Database > Mysql Tutorial > body text

How to Fix the \'Trying to get property of non-object\' Error in CodeIgniter Form Elements?

Patricia Arquette
Release: 2024-10-25 11:44:02
Original
283 people have browsed it

How to Fix the

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>
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!