I'm developing a website, some users will access it, and I need the password to expire every 30 days . I did this check, but it never crashes, even when the if is true. If anyone has any idea what might be wrong or a tip to improve, thank you. Below is the code in PHP .
$cnpj = $_POST['cnpj'];
$senha = $_POST['senha'];
$hoje = date('Y-m-d');
$conexao = mysqli_connect('localhost','root','') or print(mysqli_error());
$db = mysqli_select_db($conexao, 'teste') or print(mysqli_error());
$sql = "SELECT * FROM usuario WHERE cnpj = '$cnpj' AND senha = '$senha'";
$sql2 = "UPDATE usuario SET senha = 'expirou' WHERE cnpj = '$cnpj' and NOW() > data_senha";
$sql3 = "UPDATE usuario SET data_senha = NOW() WHERE cnpj = '$cnpj'";
$sql4 = "SELECT data_senha FROM usuario WHERE cnpj = '$cnpj'";
$resultado_login = mysqli_query($conexao, $sql);
$data_senha = mysqli_query($conexao, $sql4);
if ($hoje >= $data_senha) {
echo "<script> window.alert('Sua senha expirou! Entre em contato com a Rofran e solicite a nova senha.'); </script>";
echo "<script> window.location.replace('../index.html'); </script>";
$update_senha = mysqli_query($conexao,$sql2);
$update_data_senha = mysqli_query($conexao,$sql3);
}elseif(mysqli_num_rows($resultado_login) == 0){
header("Location: ../erro.html");
session_destroy();
}else{
header("Location:../home.html");
session_start();
}
I tested both date and return values, but in these tests I also noticed that they are not of the same type, even though they have the same yyyy-mm-d format.