Same name and namespace in other branches
  1. 4.6.x developer/hooks/node.php \hook_insert()
  2. 4.7.x developer/hooks/node.php \hook_insert()
  3. 6.x developer/hooks/node.php \hook_insert()
  4. 7.x modules/node/node.api.php \hook_insert()

Respond to node insertion.

This is a hook used by node modules. It is called to allow the module to take action when a new node is being inserted in the database by, for example, inserting information into related tables.

Parameters

$node: The node being inserted.

Return value

None.

To take action when nodes of any type are inserted (not just nodes of the type(s) defined by this module), use hook_nodeapi() instead.

For a detailed usage example, see node_example.module.

Related topics

6 functions implement hook_insert()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

book_insert in modules/book/book.module
Implementation of hook_insert().
fileupload_insert in developer/examples/fileupload.module
Implementation of hook_insert().
forum_insert in modules/forum/forum.module
Implementation of hook_insert().
node_example_insert in developer/examples/node_example.module
Implementation of hook_insert().
poll_insert in modules/poll/poll.module

... See full list

File

developer/hooks/node.php, line 302
These hooks are defined by node modules, modules that define a new kind of node.

Code

function hook_insert($node) {
  db_query("INSERT INTO {mytable} (nid, extra)\n    VALUES (%d, '%s')", $node->nid, $node->extra);
}