Submission of Adapted Contribution Plugin Returns Zend error

I’m adapting Our Marathon’s contribution plugin (which was adapted from the original) for a new project. I’m getting the following error on form submission:

Omeka has encountered an error

Zend_Db_Statement_Mysqli_Exception
Mysqli statement execute error : No data supplied for parameters in prepared statement

I can provide the entire stack trace if necessary. I think it’s probably getting a null value somewhere, but I don’t know how to find out where.

Also–for future debugging–am I supposed to read that stack from top to bottom or bottom to top?

Yep. That sounds like a null value, maybe something that isn’t being set as expected. Broadening the exception report to include Notices can often help, as those will reveal unset stuff a little before it completely borks.

The stack trace will help. (Post it with three backticks before and after):

stuff

“stuff” there has the three bacticks before and after

Depending on what’s on the server, it can sometimes go either direction. Look for a line with main, and that’ll give the starting point, and go up or down from there.

Okay, here’s the full stack via the WYSIWYG editor’s code block button:

exception 'Zend_Db_Statement_Mysqli_Exception' with message 'Mysqli statement execute error : No data supplied for parameters in prepared statement' in /home/militar1/public_html/dev/application/libraries/Zend/Db/Statement/Mysqli.php:214
Stack trace:
#0 /home/militar1/public_html/dev/application/libraries/Zend/Db/Statement.php(303): Zend_Db_Statement_Mysqli->_execute(Array)
#1 /home/militar1/public_html/dev/application/libraries/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#2 [internal function]: Zend_Db_Adapter_Abstract->query(Object(Omeka_Db_Select), Array)
#3 /home/militar1/public_html/dev/application/libraries/Omeka/Db.php(79): call_user_func_array(Array, Array)
#4 /home/militar1/public_html/dev/application/libraries/Omeka/Db/Table.php(648): Omeka_Db->__call('query', Array)
#5 /home/militar1/public_html/dev/application/libraries/Omeka/Db/Table.php(648): Omeka_Db->query(Object(Omeka_Db_Select), Array)
#6 /home/militar1/public_html/dev/application/libraries/Omeka/Db/Table.php(281): Omeka_Db_Table->fetchObjects(Object(Omeka_Db_Select))
#7 /home/militar1/public_html/dev/plugins/Geolocation/models/Location.php(30): Omeka_Db_Table->findBy(Array)
#8 /home/militar1/public_html/dev/application/libraries/Omeka/Record/AbstractRecord.php(383): Location->_validate()
#9 /home/militar1/public_html/dev/application/libraries/Omeka/Record/AbstractRecord.php(533): Omeka_Record_AbstractRecord->isValid()
#10 /home/militar1/public_html/dev/plugins/Geolocation/GeolocationPlugin.php(207): Omeka_Record_AbstractRecord->save()
#11 /home/militar1/public_html/dev/plugins/Geolocation/GeolocationPlugin.php(463): GeolocationPlugin->hookAfterSaveItem(Array)
#12 [internal function]: GeolocationPlugin->hookContributionSaveForm(Array)
#13 /home/militar1/public_html/dev/application/libraries/Omeka/Plugin/Broker.php(157): call_user_func(Array, Array)
#14 /home/militar1/public_html/dev/application/libraries/globals.php(188): Omeka_Plugin_Broker->callHook('contribution_sa...', Array)
#15 /home/militar1/public_html/dev/plugins/Contribution/controllers/ContributionController.php(239): fire_plugin_hook('contribution_sa...', Array)
#16 /home/militar1/public_html/dev/plugins/Contribution/controllers/ContributionController.php(63): Contribution_ContributionController->_processForm(Array)
#17 /home/militar1/public_html/dev/application/libraries/Zend/Controller/Action.php(516): Contribution_ContributionController->contributeAction()
#18 /home/militar1/public_html/dev/application/libraries/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch('contributeActio...')
#19 /home/militar1/public_html/dev/application/libraries/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#20 /home/militar1/public_html/dev/application/libraries/Zend/Application/Bootstrap/Bootstrap.php(105): Zend_Controller_Front->dispatch()
#21 /home/militar1/public_html/dev/application/libraries/Zend/Application.php(384): Zend_Application_Bootstrap_Bootstrap->run()
#22 /home/militar1/public_html/dev/application/libraries/Omeka/Application.php(79): Zend_Application->run()
#23 /home/militar1/public_html/dev/index.php(23): Omeka_Application->run()
#24 {main}

huh. a bit of a mystery. It looks like the problem is in the Geolocation plugin, in the afterSaveItem hook. It looks like it doesn’t have an item id, which is kind of odd for running after save.

I’d start with making sure Geolocation is up to date. If the problem is still there, try deactivating it to try to narrow down where there problem is.

In the trace look for lines that refer to files with Geolocation in the path. In the above trace, line #7 looks like where things start to go awry.

Just updated to newest version of Geolocation plugin, same error. Deactivated plugin and am now getting a different error:

exception 'Zend_Db_Statement_Mysqli_Exception' with message 'Mysqli prepare error: Unknown column 'contact' in 'field list'' in /home/militar1/public_html/dev/application/libraries/Zend/Db/Statement/Mysqli.php:77
Stack trace:
#0 /home/militar1/public_html/dev/application/libraries/Zend/Db/Statement.php(115): Zend_Db_Statement_Mysqli->_prepare('INSERT INTO `om...')
#1 /home/militar1/public_html/dev/application/libraries/Zend/Db/Adapter/Mysqli.php(388): Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Mysqli), 'INSERT INTO `om...')
#2 /home/militar1/public_html/dev/application/libraries/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Adapter_Mysqli->prepare('INSERT INTO `om...')
#3 [internal function]: Zend_Db_Adapter_Abstract->query('INSERT INTO `om...', Array)
#4 /home/militar1/public_html/dev/application/libraries/Omeka/Db.php(79): call_user_func_array(Array, Array)
#5 /home/militar1/public_html/dev/application/libraries/Omeka/Db.php(252): Omeka_Db->__call('query', Array)
#6 /home/militar1/public_html/dev/application/libraries/Omeka/Db.php(252): Omeka_Db->query('INSERT INTO `om...', Array)
#7 /home/militar1/public_html/dev/application/libraries/Omeka/Record/AbstractRecord.php(543): Omeka_Db->insert('ContributionCon...', Array)
#8 /home/militar1/public_html/dev/plugins/Contribution/controllers/ContributionController.php(309): Omeka_Record_AbstractRecord->save()
#9 /home/militar1/public_html/dev/plugins/Contribution/controllers/ContributionController.php(242): Contribution_ContributionController->_linkItemToContributedItem(Object(Item), NULL, Array)
#10 /home/militar1/public_html/dev/plugins/Contribution/controllers/ContributionController.php(63): Contribution_ContributionController->_processForm(Array)
#11 /home/militar1/public_html/dev/application/libraries/Zend/Controller/Action.php(516): Contribution_ContributionController->contributeAction()
#12 /home/militar1/public_html/dev/application/libraries/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch('contributeActio...')
#13 /home/militar1/public_html/dev/application/libraries/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#14 /home/militar1/public_html/dev/application/libraries/Zend/Application/Bootstrap/Bootstrap.php(105): Zend_Controller_Front->dispatch()
#15 /home/militar1/public_html/dev/application/libraries/Zend/Application.php(384): Zend_Application_Bootstrap_Bootstrap->run()
#16 /home/militar1/public_html/dev/application/libraries/Omeka/Application.php(79): Zend_Application->run()
#17 /home/militar1/public_html/dev/index.php(23): Omeka_Application->run()
#18 {main}

The NULL value on line #9 is trying to find the contributor:

// Allow plugins to deal with the inputs they may have added to the form.
            fire_plugin_hook('contribution_save_form', array('contributionType'=>$contributionType,'item'=>$item, 'post'=>$post));
            $item->save();
            
            $this->_linkItemToContributedItem($item, $contributor, $post);  //ContributionController.php(242)
            $this->_sendEmailNotifications($user->email, $item);
            return true;

Indeed, $contributor there looks null, which would surely cause problems. I’m guessing that what you really want there is $user instead of $contributor.

That said, there’s another error that’s happening before that problem makes everything break down. The exception’s message, Unknown column 'contact' in 'field list' signals that there’s something funky between the data you’re trying to save to the database, and what’s actually set up in the database.

The ContributionContributedItem model looks right, having a public $contact property, but the installation of the plugin looks like it doesn’t add that column to the table:

        $sql = "CREATE TABLE IF NOT EXISTS `$db->ContributionContributedItem` (
            `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
            `item_id` INT UNSIGNED NOT NULL,
            `public` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
            `anonymous` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
            PRIMARY KEY (`id`),
            UNIQUE KEY `item_id` (`item_id`)
            ) ENGINE=MyISAM;";
        $this->_db->query($sql);

So, it looks like the change to using $user instead of $contributor, and more importantly adding the contact column to the table when you install, should get things running. I suspect that if that works okay, then reactivating Geolocation will work okay, too.

I was able to add a contact column to the table (THANK YOU!) But am now getting another SQL error:

   Zend_Db_Statement_Mysqli_Exception
    Mysqli prepare error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''omek_element_sets' WHERE 'record_type' = 'UserProfilesType'' at line 1

exception 'Zend_Db_Statement_Mysqli_Exception' with message 'Mysqli prepare error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''omek_element_sets' WHERE 'record_type' = 'UserProfilesType'' at line 1' in /home/militar1/public_html/dev/application/libraries/Zend/Db/Statement/Mysqli.php:77
Stack trace:
#0 /home/militar1/public_html/dev/application/libraries/Zend/Db/Statement.php(115): Zend_Db_Statement_Mysqli->_prepare('SELECT DISTINCT...')
#1 /home/militar1/public_html/dev/application/libraries/Zend/Db/Adapter/Mysqli.php(388): Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Mysqli), 'SELECT DISTINCT...')
#2 /home/militar1/public_html/dev/application/libraries/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Adapter_Mysqli->prepare('SELECT DISTINCT...')
#3 /home/militar1/public_html/dev/application/libraries/Zend/Db/Adapter/Abstract.php(794): Zend_Db_Adapter_Abstract->query('SELECT DISTINCT...', Array)
#4 [internal function]: Zend_Db_Adapter_Abstract->fetchCol('SELECT DISTINCT...')
#5 /home/militar1/public_html/dev/application/libraries/Omeka/Db.php(79): call_user_func_array(Array, Array)
#6 /home/militar1/public_html/dev/plugins/Contribution/controllers/ContributionController.php(331): Omeka_Db->__call('fetchCol', Array)
#7 /home/militar1/public_html/dev/plugins/Contribution/controllers/ContributionController.php(331): Omeka_Db->fetchCol('SELECT DISTINCT...')
#8 /home/militar1/public_html/dev/plugins/Contribution/controllers/ContributionController.php(245): Contribution_ContributionController->_addElementTextsToItem(Object(Item), Array)
#9 /home/militar1/public_html/dev/plugins/Contribution/controllers/ContributionController.php(63): Contribution_ContributionController->_processForm(Array)
#10 /home/militar1/public_html/dev/application/libraries/Zend/Controller/Action.php(516): Contribution_ContributionController->contributeAction()
#11 /home/militar1/public_html/dev/application/libraries/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch('contributeActio...')
#12 /home/militar1/public_html/dev/application/libraries/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#13 /home/militar1/public_html/dev/application/libraries/Zend/Application/Bootstrap/Bootstrap.php(105): Zend_Controller_Front->dispatch()
#14 /home/militar1/public_html/dev/application/libraries/Zend/Application.php(384): Zend_Application_Bootstrap_Bootstrap->run()
#15 /home/militar1/public_html/dev/application/libraries/Omeka/Application.php(79): Zend_Application->run()
#16 /home/militar1/public_html/dev/index.php(23): Omeka_Application->run()
#17 {main}

I dug around the tables through phpmyadmin and it looks like it’s creating the table, but it isn’t creating any columns. This is the adapted code for that table:

$sql = "CREATE TABLE IF NOT EXISTS `$db->ContributionContributedItem` (
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `item_id` INT UNSIGNED NOT NULL,
    `public` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
    `anonymous` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
    `contact` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`),
    UNIQUE KEY `item_id` (`item_id`)
    ) ENGINE=MyISAM;";
$this->_db->query($sql); 

Additionally, the item IS getting added to the site, associated with the correct user ID, and all uploads are working fine BUT any user input of metadata isn’t being recorded. Thoughts?