Wednesday 26 January 2011

Module to record the username of a user when they access a page?

We've been asked to come up with a module that can be embedded in a page and will insert into a database table the username of the user accessing that page.  I've tried Google searching but can't find anything.

I did find a forum post that talks about doing something similar:
  • Create the table using:
    CREATE TABLE `databasename`.`jos_names` (`id` int(11) NOT NULL auto_increment, `firstname` VARCHAR(100), `lastname` VARCHAR(100), PRIMARY KEY  (`id`) )

  • Then write your module using: $db =& JFactory::getDBO();
    $query = "INSERT INTO `#__names` (`fname`, `lname`)
    VALUES ($fname, $lname);";
    $db->setQuery( $query );
    $db->query();

No comments:

Post a Comment