Home > Database > Mysql Tutorial > How to Fix the \'Trying to Get Property of Non-Object\' Error in CodeIgniter Update Forms?

How to Fix the \'Trying to Get Property of Non-Object\' Error in CodeIgniter Update Forms?

Susan Sarandon
Release: 2024-10-25 05:50:02
Original
297 people have browsed it

How to Fix the

Troubleshooting "Trying to Get Property of Non-Object" Error in CodeIgniter

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:

  1. Object Notation: $product->prodname
  2. Array Notation: $product['prodname']

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

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!

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