用户单击链接时插入click_url,时间戳和用户名

i was going to have a menu consisting of images which differed depending on if a new record was added since the users last visit.

However I decided to move away from that idea and I am now going for comparing last timestamp on clicked link with timestamp on new record.

I tried to find a solution but I am stuck at this line right now, maybe you can see what's wrong with it (clicks is my table where I want to store the clicks):

$sql = "insert into clicks (username, link_url, click_timestamp) values ($_SESSION[$username], "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", now())";
$result=mysql_query($sql);

So, anybody have any good ideas? :)

You have an error in your SQL syntax, try this:

$sql = 'INSERT INTO clicks (username, link_url, click_timestamp) VALUES
        ("' . $_SESSION[$username] . '",  
         "http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '", 
          NOW()
        )';

Check that string. As ar as I know, PHP can solve plain variables inside a string, but cannot solve an array, so $_SESSION in this case should go outside the string. Also, if you want to put quotes inside a string, use a backslash before it, like \", so it's gonna be interpreted as a quote character instead of an end of string.