A number of problems.  First and foremost you're extracting multiple
rows from the database table are you not?  Therefore you must increment
through them in some way.  I like to embed my mysql_fetch_xxx()
functions in a while() loop.

-----------------------------------------------
while ($row = mysql_fetch_array($sql_result))
{
        // Check to see if this IP Address was previously recorded.
        $exists = 0;
        if ($proxy_ip == $row["accessIP"])
        {
                $exists = 1;
                break;
        }
}

// IF the IP exists do this thing ELSE do that other thing.
if ($exists)
{
        // Update view where ip = visitor_ip
        mysql_query("UPDATE access SET accessVIEW =
                accessVIEW+1 WHERE accessIP = $proxy_ip");
}
else
{

        // do this other stuff...

}
-----------------------------------------------

Remember the WHILE() loops.  By the way there's a fantastic book that
talks all about this stuff called, "PHP and MySQL Web Development" by
Luke Welling & Laura Thomson.  It is an invaluable source of real-world
examples.
Hope this helps.
-Kevin


-----Original Message-----
From: Philip J. Newman [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, March 20, 2002 1:58 PM
To: [EMAIL PROTECTED]
Subject: [PHP] [Newman] updating a mysql record if IP # is the same.

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.






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to