Home > Database > Mysql Tutorial > body text

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

Susan Sarandon
Release: 2024-10-24 19:24:29
Original
245 people have browsed it

How to Fix

Error: "Trying to Get Property of Non-Object" 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>
Copy after login

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!

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!