Jump to content

Recommended Posts

Him
I have an OTP sysem where the user will enter the OTP that was sent to their email, in the DB it is saving the OTP and the expiry after 15 minutes. After they use it, I need to delete both from DB. I am able to set the number back to 0 since it is an integer. How to reset the dattime field to show 0000-00-00 00:00:00?

$sqlUpdate = "UPDATE login_users SET otp_reset = 0, otp_expiry = ??? WHERE username_email = '$myusername'";
if(mysqli_query($db,$sqlUpdate))
{
.....
}

 

Link to comment
https://forums.phpfreaks.com/topic/327530-put-the-default-value-of-datetime/
Share on other sites

First off, don't inject variables directly into a query like that - use prepared statements. Secondly, if it's not too late already I recommend switching to the PDO database interface - it's much easier to work with and reason about.

Now, as to your actual question, set the value to null.

$qry = "
	UPDATE login_users
	SET	 otp_reset = 0
		,otp_expiry = :exp
	WHERE username_email = :email
";
$sql = $pdoObject->prepare($qry);
$result = $sql->execute($qry, [
	'exp' => null,
	'email' => $myusername
]);

Admittedly, I've been in the land of Laravel for about 5 years now and am not entirely sure of my syntax above, so take it with a grain of salt...

Edited by maxxd

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.