How to insert data into node and other tables at the same time? I create a Drupal module which install database tables during module installation, table is created using Drupal way. The tables are created perfectly and now i have to insert data into those tables.

Example table structure where i want data to be inserted in sequence :


Node (insert product name)
myproduct_category (take the inserted node id and save the product category and nid at the same time in this table)
myproduct_price (take the inserted node id and save the product price and nid at the same time in this table)


Once data are inserted into database, the site admin will retrieve those saved data and show it in front-end.

here's my current code to insert data into node, i just can't get the last inserted id and continue insert data into other tables :

            $node   = new stdClass();
            $node-&gt;title    = $val['ADDRESS_1'];
            $node-&gt;type     = 'basil_veco';
            node_object_prepare($node);
            $node-&gt;language = LANGUAGE_NONE;
            $node-&gt;uid      = $user-&gt;uid;
            $node-&gt;status   = 1;
            $node-&gt;promote  = 0;
            $node-&gt;comment  = 0;
            $node-&gt;created  = timestamp;

            $node = node_submit($node); // Prepare node for saving      
            node_save($node);


Please tell me the way to go about if my approach is not the right way.

Thank you.
Why you are using custom code to store the records in the node table. Are you calling any API service or you creating form yourself? 

If you have created content type, then just go with drupal way and call custom submit function to store products and price values in a separate table by using db_write_record() or db_insert() function to insert the record in the database. 

Just go through the below link

https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_write_record/7
https://www.drupal.org/node/310079