Can I create a rule on my drupal 7 website and that rule will:

Whenever a user is logged in (only logged in users can see this content) and a certain content is clicked I want to write a mysql update statement to my database. The user name of that person and what content was clicked.

I know I can execute PHP code for my action but not sure if I need to somehow convert mysql and php together? please if anyone knows and could give a fairly detailed instructions I would appreciate it greatly!


Instead of creating a security breach in your site (logged in user is not bullet proof and relies maybe a bit too much on trust of user's sense of responsability considering keeping strong password and clean browsers, closing sessions...), I would suggest to look into the existing statistics module and match the objective by configuration and customisation. It is not possible to give you the right answer because it depends on a lot of variables, but here are a few links to dig and find your solution:

Statistics documentation:

Google Analytics modules:

I think you could do pretty much what you want with GA + Rules: https://www.drupal.org/node/37694,

Other statistics modules:

EDIT : Also you could use views to generate an output of the necessary information and an export in csv to make it even better


Yes you can use PHP within some custom rule, and then include your SQL statements. But that requires PHP code to be stored in your Drupal database ... which is bad (repeat: bad).

I recommend you to not go that path. But instead you should use the Message module, to create the equivalent of those database records you want to create.

Have a look at my answer to "How to create audit trails/order revisions?", which is like a variation of your question, and which explains how the Message module integrates with the Rules module to get this to work. Did I mention zero custom (PHP) code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.