Jump to content

Recommended Posts

[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..

Link to comment
https://forums.phpfreaks.com/topic/11751-adding-from-timestamps-in-mysql/
Share on other sites

[!--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
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]
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.
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.