Update Time on MySQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • miguel22
    New Member
    • Jan 2008
    • 13

    Update Time on MySQL

    Hi,

    I have a table with 4 different columns to record IP address of people visiting my site. If a new IP comes it is recorded and a time also written on the last column.

    The problem is when an exisiting IP comes again. The time becomes "0000-00-00".

    Here is the code after you already connect with the database and an IP is found on the database or not.

    Note: $Username_Found is a variable == 1 when an IP address is already found on the database. Default is not found == 0.
    [code=php]
    if ($Username_Foun d == 1){
    $counter = $counter + 1;
    mysql_query("UP DATE IPLog SET TimesVisit = $counter WHERE User_IP = '$ip'");
    mysql_query("UP DATE IPLog User_Time = $User_Time WHERE User_IP = '$ip'");
    }
    if ($Username_Foun d == 0){
    $IPCount = $IPCount + 1;
    $TimesVisit = 1;
    $sql="INSERT INTO IPLog (IPCount,User_I P, TimesVisit, User_Time)
    VALUES
    ('$IPCount','$i p','$TimesVisit ','$User_Time') ";

    if (!mysql_query($ sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    }
    [/code]

    Thank you.
    Last edited by Atli; Jul 23 '08, 01:11 AM. Reason: Added [code] tags
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    You have missed out SET in your second query.
    Why not write it as one?
    Code:
    mysql_query("UPDATE IPLog SET TimesVisit = $counter,IPLog User_Time = $User_Time WHERE User_IP = '$ip'");

    Comment

    • miguel22
      New Member
      • Jan 2008
      • 13

      #3
      Thank you. I have tried with SET on both, sorry to post it without SET on the second set.

      I will try it with only one string and check. I thought the problem was on write the date as variable.

      Thanks.

      Comment

      Working...