Jump to content

PHP any mysql anylitics code


jackr1909

Recommended Posts

Hi i have this anylitics code:

 

<?php
$con = mysql_connect("localhost","root","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (id, url,  ip, referringurl, date, time)
VALUES ('', '{$_GET['S']', '$_SERVER['REMOTE_ADDR']', '$SERVER['URL_REFER'], '', '')");

mysql_query("i don't know the syntax for hits");

mysql_close($con);
?> 

 

it isn't working.

 

i can use an external config file if necessary but what i basically want to do is insert the referring url, users IP, time, date, and increase a value in the 'hits' table for every query. Time and date added in mysql

Link to comment
Share on other sites

Your missing a } inside the query for $_GET, which is unprotected and this can be a security issue (see mysql_real_escape_string)

 

date and time are reserved I believe, hence you need the TICKS ``

 

You are also missing a single quote

 

$con = mysql_connect("localhost","root","abc123");

if (!$con)  {  die('Could not connect: ' . mysql_error());  }
mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (`id`, `url`,  `ip`, `referringurl`, `date`, `time`) VALUES  ('', '{$_GET['S']}', '{$_SERVER['REMOTE_ADDR']}', '{$SERVER['URL_REFER']}', '', '')");

 

for the hits value, see mysql UPDATE

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.