Jump to content

$time = time(); + MySQL? Doesn't work WTF? Help please.


Technex

Recommended Posts

Hey guys, here's my code:

 

 

 

$ip = $_SERVER['REMOTE_ADDR'];

$time = time();

 

mysql_query("INSERT INTO guests

(ip,lastactive) VALUES('$ip','$time') ");

 

 

 

It's for a online guest counter, could you help me fix it for some reason it won't input lastactive like there's a problem with the PHP time function.

 

Thanks ;).

Link to comment
Share on other sites

Thanks for the response.

 

Out of range value adjusted for column 'lastactive' at row 1

 

ip is a varchar(90) - ascii_general_ci column.

 

lastactive tinyint(50) I just went pretty big to get it working.

Link to comment
Share on other sites

You might want to change your "lastactive" field to the TIME type.

 

#1292 - Incorrect time value: '1184522514' for column 'lastactive' at row 1

 

:( varchar(40) fixed it. Thanks for your help :). Is this wise though?

Link to comment
Share on other sites

Well, you could also try setting the field to TIMESTAMP, as I think that is what the time() function gives you.

 

Well so far

 

TIMESTAMP

TIME

DATETIME

 

haven't worked :(. What else is good to use?

 

Thanks.

Link to comment
Share on other sites

Well if that's good Mysql practice then okay :).

 

I have another problem :(.

 

lastactive in the users database

 

if(isset($userinfo[id])) {

mysql_query("UPDATE users SET lastactive='$lastactive' WHERE id='$userinfo[id]'");

}

 

It just creates a blank MySql entry.

 

lastactive  varchar(70)  ascii_general_ci      No

Link to comment
Share on other sites

I guess thats to say somene is online / offline? 1 being online..

if so i'd suggest using a "Users online within the last 5 minute"

By adding a timestamp every page they view....

 

$time = date("j-m-Y, H:i:s", strtotime("now"));

that to set the time stamp.

 

then use this to check last 5 mins

 

$mins = date("j-m-Y, H:i:s", strtotime("- 5 Minutes"));

mysql_query("SELECT * FROM `users` WHERE `status` < '$mins'");

Link to comment
Share on other sites

Sorry redarrow I done a ninja edit on you, I tried to be as fast as I could. I fixed the problem I posted and I changed to another one I had.

 

xyn I have a system like that ;). The only problem is on MySql side. Not very good with Mysql.

 

 

Thanks everyone :).

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.