Hi all,
I'm new to drupal.
I have a button in display page of a node.

If i click the button in the page,it should fetch the currently logged in user id and the node id of the node where button belongs to and insert those id's into the custom table i created.Please give suggestions. Thanks in advance.

Comments

dibyajyoti.mallick’s picture

Hi,

For that you need to create custom module and put below piece of code in to the module class method and call that method in button click.

if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
if ($nid) {

$nodeId = node_load($nid);

global $user;
$user_id = $user->uid;

$nid = db_insert('your_table_name')
->fields(array(
'node_id' => $nodeId,
'user_id' => $user_id,
))
->execute();

}
}

Please let me know if you have any doubt.

Thanks,
Dibyajyoti