so I'm trying to make a set a new password page
I have a forgot password page where I'm sending an email to the user by generating a token which will help me to make the link usable only once, once the password was generated the token will become NULL
this is the template of the link
$url = "..../test.php?token=$str&email=$email";
I get the link on my email then when I open the page I get the error if the token is not ok
<form action="test.php" method="post" class="login100-form validate-form">
<div class="wrap-input100 validate-input m-b-50" data-validate="Enter password">
<input type="password" class="input100" name="lalala" required/>
<span class="focus-input100" data-placeholder="Parola"></span>
</div>
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
if (isset($_GET["token"]) && isset($_GET["email"])) {
$connection = new mysqli('myhostr.com', 'xxxxxxxxx', 'xxxxxxxxx', 'xxxxxx');
$email = $connection->real_escape_string($_GET["email"]);
$token = $connection->real_escape_string($_GET["token"]);
$data = $connection->query("SELECT id FROM users WHERE email='$email' AND token='$token' AND token <> '' ");
if (isset($_POST["register"]))
if ($data->num_rows > 0)
{
$str = $connection->real_escape_string($_POST["lalala"]);
$password = sha1($str);
$connection->query("UPDATE users SET password = '$password', token = '' WHERE email='$email'");
echo "<div class='alert success'>
New password is: $str
</div>";}
if ($data->num_rows > 0)
{
echo "<div class='alert'>
<span class='closebtn'>×</span>
Invalid link!
</div>";
}
} else {
header("Location: login.php");
exit();
}
?>
<input type="submit" class="login100-form-btn" name="register" value="Inregistrare" required />
<br><br>
</form>
if the token is not ok I get the error, but if i have the good token and i press the register button it will redirect me to the login.php page and in the database, the password will be unchanged and the token will be the same ( not NULL as it should).
and I have no errors.