We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

EE save_entry API generates 'Column not found: 1054 Unknown column' error

Development and Programming

Joshua Bunting's avatar
Joshua Bunting
1 posts
7 years ago
Joshua Bunting's avatar Joshua Bunting

I’ve got a new install of EE 4.2.1 setup and running and when I try to use the legacy API to save an entry on the fly, its throwing a ‘Column not found: 1054 Unknown column’ error. Looking at the database its clear that the new way EE handles channel fields as separate tables is the conflict. However, I had assumed that the API would be updated to adapt to the new setup. Is there a work around for this or an update that can address it?

My php code:

ee()->load->library('api');
ee()->session->userdata['group_id'] = 1;
ee()->session->userdata['member_id'] = 1; 
ee()->legacy_api->instantiate('channel_entries');
ee()->legacy_api->instantiate('channel_fields');

$entrydata = array(
                'title'         => $useForSubject,
                'field_id_8'    => "test",
                'field_id_4'    => $useForMainText,
                'field_id_14'   => $email
);

ee()->api_channel_fields->setup_entry_settings(7, $entrydata);
$success = ee()->api_channel_entries->save_entry($entrydata, 7);
            
if ( ! $success)
{
         show_error(implode('', $this->api_channel_entries->errors));
}

Error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_id_8' in 'field list':
 INSERT INTO `exp_channel_data` (`entry_id`, `channel_id`, `site_id`, `field_id_8`, `field_id_4`, `field_id_14`, `field_ft_1`, `field_id_1`, `field_ft_2`, `field_id_2`, `field_ft_3`, `field_id_3`, `field_ft_4`, `field_ft_5`, `field_id_5`, `field_ft_6`, `field_id_6`, `field_ft_7`, `field_id_7`, `field_ft_8`, `field_ft_10`, `field_id_10`, `field_ft_11`, `field_id_11`, `field_ft_12`, `field_id_12`, `field_ft_13`, `field_id_13`, `field_ft_14`, `field_ft_15`, `field_id_15`) VALUES ('20', 7, 1, 'Test', 'Test', NULL, 'none', '', 'none', '', 'none', '', 'none', 'none', '', 'xhtml', '', 'none', '', 'none', 'none', '', 'none', '', 'none', '', 'none', '', 'xhtml', 'none', '')

ee/legacy/database/drivers/mysqli/mysqli_connection.php:116
Stack Trace: Please include when reporting this error

    #0 ee/legacy/database/drivers/mysqli/mysqli_driver.php(111): CI_DB_mysqli_connection->query('INSERT INTO `ex...')
    #1 ee/legacy/database/DB_driver.php(269): CI_DB_mysqli_driver->_execute('INSERT INTO `ex...')
    #2 ee/legacy/database/DB_driver.php(179): CI_DB_driver->simple_query('INSERT INTO `ex...')
    #3 ee/legacy/database/DB_active_rec.php(1370): CI_DB_driver->query('INSERT INTO `ex...')
    #4 ee/legacy/libraries/api/Api_channel_entries.php(1220): CI_DB_active_record->insert('channel_data', Array)
    #5 ee/legacy/libraries/api/Api_channel_entries.php(172): Api_channel_entries->_insert_entry(Array, Array, Array)
    #6 ee/legacy/libraries/Functions.php(626) : eval()'d code(155): Api_channel_entries->save_entry(Array, 7)
    #7 ee/legacy/libraries/Functions.php(626): eval()
    #8 ee/legacy/libraries/Template.php(1980): EE_Functions->evaluate('{!-- ra:0000000...')
    #9 ee/legacy/libraries/Template.php(564): EE_Template->parse_template_php('{!-- ra:0000000...')
    #10 ee/legacy/libraries/Template.php(230): EE_Template->parse('{!-- ra:0000000...', true, 1, false)
    #11 ee/legacy/libraries/Template.php(1110): EE_Template->fetch_and_parse('join-our-team', 'detail', true, 1)
    #12 ee/legacy/libraries/Template.php(601): EE_Template->process_sub_templates('{!-- ra:0000000...')
    #13 ee/legacy/libraries/Template.php(230): EE_Template->parse('{!-- ra:0000000...', false, 1, false)
    #14 ee/legacy/libraries/Template.php(163): EE_Template->fetch_and_parse('', Array, false)
    #15 ee/legacy/libraries/Core.php(665): EE_Template->run_template_engine('', '')
    #16 ee/legacy/controllers/ee.php(62): EE_Core->generate_page()
    #17 [internal function]: EE->index()
    #18 ee/EllisLab/ExpressionEngine/Core/Core.php(240): call_user_func_array(Array, Array)
    #19 ee/EllisLab/ExpressionEngine/Core/Core.php(109): EllisLab\ExpressionEngine\Core\Core->runController(Array)
    #20 ee/EllisLab/ExpressionEngine/Boot/boot.php(146): EllisLab\ExpressionEngine\Core\Core->run(Object(EllisLab\ExpressionEngine\Core\Request))
    #21 index.php(172): require_once('...')
    #21 index.php(172): require_once('...')
       
PaleoSun's avatar
PaleoSun
5 posts
6 years ago
PaleoSun's avatar PaleoSun

What type of field is field_id_8? If it’s a grid type, then I think you need to set the rows/columns with the grid like this:

$entrydata[‘field_id_8’][‘rows’][‘new_row_1’)][‘col_id_’ . $col_id] = ‘value’;

where col_id is the column name with the exp_channel_grid_field_8

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.