birdie Posted June 11, 2006 Share Posted June 11, 2006 [code]$ip = $_SERVER['REMOTE_ADDR'];$sql = "SELECT * FROM portal_logintrys WHERE ip='$ip'";$query = mysql_query($sql);$numrows = mysql_num_rows($query);$object = mysql_fetch_object($query);if($numrows == "0"){$sql = "INSERT INTO portal_logintrys ('ip','times') VALUES ('$ip','1')";}else{$times2 = $object->times;$times2++;$sql = "UPDATE portal_logintrys SET times='$times2' WHERE ip='$ip'";}mysql_query($sql);[/code]completely confused, please tell me why this script wont even touch mysql.. Quote Link to comment https://forums.phpfreaks.com/topic/11751-adding-from-timestamps-in-mysql/ Share on other sites More sharing options...
Buyocat Posted June 11, 2006 Share Posted June 11, 2006 You don't seem to be connecting to the database, at least not in the code you've shown, so that would be a necessary first step. What error do you get when you run that code? Quote Link to comment https://forums.phpfreaks.com/topic/11751-adding-from-timestamps-in-mysql/#findComment-44443 Share on other sites More sharing options...
birdie Posted June 11, 2006 Author Share Posted June 11, 2006 [!--quoteo(post=382677:date=Jun 12 2006, 12:05 AM:name=Buyocat)--][div class=\'quotetop\']QUOTE(Buyocat @ Jun 12 2006, 12:05 AM) [snapback]382677[/snapback][/div][div class=\'quotemain\'][!--quotec--]You don't seem to be connecting to the database, at least not in the code you've shown, so that would be a necessary first step. What error do you get when you run that code?[/quote]lol trust me, i'm connected. No errors, i'm guessing the vars are messed up but i just cant see it Quote Link to comment https://forums.phpfreaks.com/topic/11751-adding-from-timestamps-in-mysql/#findComment-44453 Share on other sites More sharing options...
redarrow Posted June 11, 2006 Share Posted June 11, 2006 Try know ok.[code]$ip = $_SERVER['REMOTE_ADDR'];$sql = "SELECT * FROM portal_logintrys WHERE ip='$ip'";$query = mysql_query($sql);$numrows = mysql_num_rows($query);$object = mysql_fetch_object($query);if($numrows == "0") {$sql_insert= "INSERT INTO portal_logintrys ('ip','times') VALUES ('$ip','1')";mysql_query($sql_insert);}else{$times2 = $object->times;$times2++;$sql_update = "UPDATE portal_logintrys SET times='$times2' WHERE ip='$ip'";mysql_query($sql_update);}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11751-adding-from-timestamps-in-mysql/#findComment-44457 Share on other sites More sharing options...
poirot Posted June 12, 2006 Share Posted June 12, 2006 Just a FYI, you don't need to use the $times variable. You can UPDATE the count directly with MySQL, like:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] portal_logintrys SET times[color=orange]=[/color]times[color=orange]+[/color]1 [color=green]WHERE[/color] ip[color=orange]=[/color][color=red]'$ip'[/color] [!--sql2--][/div][!--sql3--]Also I'll suppose you are going to use this to avoid people from trying to crack passwords, but this is useless if you don't set a reset time for the attempts per IP. For this to work, you should add a field containing the timestamp of the first try. Quote Link to comment https://forums.phpfreaks.com/topic/11751-adding-from-timestamps-in-mysql/#findComment-44499 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.