0

the query is not executed i don't know why

here is my try

i use this code to delete login attempts record and ip from the tabel after 2 min to allow user to try login again

if another soultion is better than this please submit it

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="gencyolcu" />

    <title>Untitled 1</title>
</head>
<style>
.fall
{
    background-color: aliceblue;
    color: darkkhaki;
    width: 400px;
    height: 200px;
    margin-top: 200px;
    padding: 200px;
    margin-left: 200px;
}
#txt
{
    font-family: fantasy;
    font-size: xx-large;
    font-style: italic;
}
</style>
<body>

<div class="fall">
 <p id="txt">You have exceeded the allowed  login times try again 
</p>
</div>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("register_form", $con);


mysql_query("DELETE FROM login_attempts WHERE time < NOW() - INTERVAL 2 minutes");

mysql_close($con);
?>
</body>
</html>
3
  • 1
    Well, first step to fixing the problem would be to get the MySQL error. Right before you close the connection, echo mysql_error(); - this in its self might help you solve your issue. Commented May 15, 2013 at 12:59
  • 1
    Why are you deleting from the login attempts table? Can't you get a similar result if you just limit how far back you check the login attempts table? Seems if you just query the that last 2 minutes of the table you can keep the old records and know if someone is trying to loginto many accounts. Commented May 15, 2013 at 13:01
  • It's not a <= situation is it? You're not trying EXACTLY at 2 minutes out? What happens if you select * from login_attempts where time < Now() - INTERVAL 2 minutes? directly against the DB? Commented May 15, 2013 at 13:02

2 Answers 2

1

Try this (MINUTE instead of MINUTES):

sql_query("DELETE FROM login_attempts WHERE time < NOW() -  INTERVAL 2 MINUTE");
Sign up to request clarification or add additional context in comments.

6 Comments

Beat me to it. See here for the domain of values for INTERVAL: dev.mysql.com/doc/refman/5.5/en/…
@Valdogg21 Take a look at date_sub definition: DATE_SUB(date,INTERVAL expr unit). expr (second column in table you refer to) here is 2 and unit (first column) is MINUTE . And I have tested that expression before posting it here.
@TheSniper104 what type of data do you have for time column? Timestamp or datetime?
Also, how do you know it is not working? try to connect to database with PhpMyAdmin/HedySQL or something like that and execute your query.
@FAngel I was just adding the link so OP could see other possible values, not questioning your syntax :)
|
0

I think that your syntax is wrong.

Try replacing MINUTES by MINUTE

"DELETE FROM login_attempts WHERE time < NOW() - INTERVAL 2 MINUTE"

If it doesnt help, post here your MySQL error.

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.