Technex Posted July 15, 2007 Share Posted July 15, 2007 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 . Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/ Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 What is the field type for the "lastactive" in your database? EDIT: Also, try catching the error: mysql_query("INSERT INTO guests (ip,lastactive) VALUES('$ip','$time') ")or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298847 Share on other sites More sharing options...
Technex Posted July 15, 2007 Author Share Posted July 15, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298848 Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 You might want to change your "lastactive" field to the TIME type. Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298851 Share on other sites More sharing options...
Technex Posted July 15, 2007 Author Share Posted July 15, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298852 Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 Well, you could also try setting the field to TIMESTAMP, as I think that is what the time() function gives you. Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298854 Share on other sites More sharing options...
Technex Posted July 15, 2007 Author Share Posted July 15, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298870 Share on other sites More sharing options...
wildteen88 Posted July 15, 2007 Share Posted July 15, 2007 Set it INT datatype instead. Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298897 Share on other sites More sharing options...
Technex Posted July 15, 2007 Author Share Posted July 15, 2007 Set it INT datatype instead. MySQL said: Documentation #1366 - Incorrect integer value: '' for column 'lastactive' at row 1 Thanks though. Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298901 Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 Make sure you are setting the length to at least 10. INT(10) Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298904 Share on other sites More sharing options...
Technex Posted July 15, 2007 Author Share Posted July 15, 2007 Table guests has been altered. Well it changed but the whole idea doesn't even work now. When it was varchar it did :S. Any ideas why? It just doesn't put any info into MySql... Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298910 Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 Well...if Varchar was working for you, then I would just stick with that. Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298911 Share on other sites More sharing options...
Technex Posted July 15, 2007 Author Share Posted July 15, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298915 Share on other sites More sharing options...
redarrow Posted July 15, 2007 Share Posted July 15, 2007 edited sorry read ABOVE WRONG THORTS IT SUNDAY SORRY. increment by one you mean mysql_query("UPDATE `users` SET status=status+1 WHERE `id`='".$userinfo['id']."' "); Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298920 Share on other sites More sharing options...
xyn Posted July 15, 2007 Share Posted July 15, 2007 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'"); Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298922 Share on other sites More sharing options...
Technex Posted July 15, 2007 Author Share Posted July 15, 2007 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 . Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298928 Share on other sites More sharing options...
xyn Posted July 15, 2007 Share Posted July 15, 2007 heh i use AJAX Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298933 Share on other sites More sharing options...
Technex Posted July 15, 2007 Author Share Posted July 15, 2007 Okay. I still need help on this. PHP gives no error when using the or die command. It just shows a 0 in Mysql. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/60082-time-time-mysql-doesnt-work-wtf-help-please/#findComment-298963 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.