Time for action – updating an existing item

When updating a new item, the special UPDATE SQL keyword can be used. The following code updates an existing item:

db_execute("
 UPDATE `plugin_cbEnhancedInfo_dataTable`
 Set
   hostId=$s_dataHostId,
   longitude='$s_dataLongitude',
   latitude='$s_dataLatitude',
   contactAddress='$s_dataContactAddress',
   additionalInformation='$s_dataAdditionalInformation'
 WHERE
   Id='$dataId'
");

As with the creation of a new item, this code is also missing from the file. You can enter it after the comment in the following section:

 if ( (isset ($_POST['contactAddress'])) && 
     (isset ($_POST['update_component_import']) ) ) {
   /* Add Update statements here */
}

Let's look how the db_execute command will look with real data. Open a MySQL ...

Get Cacti 0.8 Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.