When your doing simple single table inserts and updates you can use the JDatabase methods to do so. The advantages of using the JDatabase methods is it saves you time from hand coding your sql and will escape and correctly quote your inputs for you.
The following will insert a new record into a table:
$db = JFactory::getDBO();
//Create data object
$row = new JObject();
$row->title = 'The Title';
$row->author = 'Bob Smith';
//Insert new record into jos_book table.
$ret = $db->insertObject('jos_book', $row);
//Get the new record id
$new_id = (int)$db->insertid();
This will update an existing record:
$db = JFactory::getDBO();
//Create data object
$row = new JObject();
//Record to update
$row->rec_id = 200;
$row->title = 'The Title';
$row->author = 'Bob Smith';
//Update the record. Third parameter is table id field that will be used to update.
$ret = $db->updateObject('jos_book', $row,'rec_id');
You can also use JTable to insert and update records, but requires more initial setup since you have to create a new JTable class for each table you want to modify. Using JTable is preferred if table has many fields to update from a form submit. JTable will automatically bind the form fields to corresponding table fields using the bind() method.
Here is more info on using JTable.
There is a way to use this code from an other script than module?
Thank you for this info .. was looking for a while how to update object list…
Kind regards