Time for action – creating a new database item
Creating
a new item is done by using an INSERT
SQL statement. The following code adds a new item to the Cacti database:
db_execute(" INSERT INTO `plugin_cbEnhancedInfo_dataTable` (`hostId`, `longitude`, `latitude`,`contactAddress`, `additionalInformation`) VALUES ($s_dataHostId, '$s_dataLongitude','$s_dataLatitude', '$s_dataContactAddress','$s_dataAdditionalInformation') ");
If you look into the cbEnhancedInfo_addInformation.php
file from Example 5, you will see that this code is actually missing. You can add it right after the comment in the following section:
if ( (isset ($_POST['contactAddress'])) && (isset ($_POST['save_component_import']) ) ) { /* Add Save statements here */ }
As you can see, the code checks for the existence of the form fields save_component_import
and contactAddress
before creating the new item. This will make sure that the function is only creating a new item (save) if data has been entered...