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
https://forums.phpfreaks.com/topic/244013-php-any-mysql-anylitics-code/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.