I have developed a login page where OTP is generated for every login of the user .The following is a button action , I have created a "generate" button once clicked it would starts a session timer and after 60 sec it should delete the varchar present in the database.
PHP Code for button :
if(isset($_POST['generate']))
{
session_start();
$_SESSION['login_time'] > 60 ;
{
$sql = "DELETE password WHERE username = ajaisandy " ;
}
Here the "password" represent the column name , once the user enters the "generate button" the session starts and gives a time period of 60 sec . The user is suppose to receive the OTP via sms and should sign in within this time if not the password stored in the DB is deleted and once again he has to perform this sequence to login.
use UPDATE instead of DELETE, also you are missing if ($_SESSION['login_time'] > 60)
if(isset($_POST['generate']))
{
session_start();
if ($_SESSION['login_time'] > 60)
{
$sql = "UPDATE TABLE_NAME SET password='' WHERE username = ajaisandy " ;
mysql_query($sql);
}
}
You should use UPDATE
instead of DELETE
:
UPDATE your_table SET password = null WHERE username = ?
And whats the condition for deleting. I guess putting an if condition in $_SESSION['login_time'] > 60
would be helpful. and are you sure about the time you are using?
first start your timer with-
$_SESSION['login_time'] = time();
now edit time checking in your code-
if(time() - $_SESSION['login_time'] > 60)
{
$sql = "DELETE password WHERE username = ajaisandy " ;
}