Jump to content


Photo

adding from timestamps in mysql


  • Please log in to reply
4 replies to this topic

#1 birdie

birdie
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationBirmingham UK

Posted 11 June 2006 - 11:03 PM


$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);


completely confused, please tell me why this script wont even touch mysql..



#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 11 June 2006 - 11:05 PM

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?
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 birdie

birdie
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationBirmingham UK

Posted 11 June 2006 - 11:41 PM

[!--quoteo(post=382677:date=Jun 12 2006, 12:05 AM:name=Buyocat)--][div class=\'quotetop\']QUOTE(Buyocat @ Jun 12 2006, 12:05 AM) View Post[/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

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 11 June 2006 - 11:55 PM

Try know ok.



$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);
}


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 12 June 2006 - 04:21 AM

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=times+1 WHERE ip='$ip' [!--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.
~ D Kuang




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users