[Newman] updating a mysql record if IP # is the same.

From: Date: Wed, 20 Mar 2002 20:58:15 +0000
Subject: [Newman] updating a mysql record if IP # is the same.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-89405@lists.php.net to get a copy of this message
What I'm trying to do: I have a log table called 'access'. When a user comes to my website there IP is logged, along with there DNS name. When they return with the same IP number the accessVIEW is updated +1 and the last number is assigned to them. Heres the Code: <?php require"config.php"; $proxy_ip=getenv('REMOTE_ADDR'); $proxy_dns=gethostbyaddr($proxy_ip); $actual_ip="$HTTP_X_FORWARDED_FOR"; $actual_dns = gethostbyaddr($HTTP_X_FORWARDED_FOR); $add_date=date ("d/F/Y @ h:i:s A"); $sql = "SELECT accessIP FROM access ORDER BY accessID DESC"; $sql_result = mysql_query($sql, $connection) or die ("Could not get Query"); $row = mysql_fetch_array($sql_result); $accessIP = $row["accessIP"]; if (mysql_num_rows($sql_result) == "$accessIP") { // Update view where ip = visitor_ip mysql_query("UPDATE access SET accessVIEW = accessVIEW+1 WHERE accessIP = $accessIP"); } else { // Normal insert $sql = "INSERT INTO access (accessID, accessIP, accessDNS, accessTIME, accessUPDATE, accessVIEW) VALUES ('', '$proxy_ip', '$proxy_dns', '$add_date', NOW(NULL), '0')"; $result = mysql_query($sql); } $sql = "SELECT accessID FROM access ORDER BY accessID DESC LIMIT 1"; $sql_result = mysql_query($sql, $connection) or die ("Could not get Query"); $row = mysql_fetch_array($sql_result); $accessNUMBER = $row["accessID"]; mysql_free_result($sql_result); mysql_close($connection); ?> Can anyone help me. This script is not working.

« previous php.general (#89405) next »