This is the way i would do it, create a mysql table named log with the following fields;
1- ID
2- log_time
3- log_ipaddress
4- log_accesspage
5- log_referrer
6- log_username
then you can do something like this (if you are posting from a form, get the variables)
<?php
// Connect to the database to store the information
include("includes/db_connection.php");
// Insert a row and get variables from form"
$sql=mysql_query("INSERT INTO log (log_time, log_ipaddress, log_accesspage, log_referrer, log_username )
VALUES ('$_POST[dtime]','$_POST[ipaddress]','$_POST[accesspage]','$_POST[referedby]','$_POST[visitorname]')");
//if you want to show a message, otherwise comment it out
echo "Data Inserted successfully!";
?>
cheers