0
I’m developing a website, in it some users will access and need to the password expires every 30 days. I did that check, but never falls into it, even when the if is true. If anyone has any idea what might be wrong or a tip to improve, thank you. Below follows 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 variables and return value, but in these tests I also noticed that they are not of the same type, even presenting the same format yyyy-mm-d.
The $today and $data_password variables are of the same type?
– Willian Coqueiro
you already tried that
var_dump(mysqli_num_rows($resultado));die;
before the if. Ever tried to put adie("alguma coisa");
inside the IF blocks, to see if it really isn’t in, or if the code inside is that it doesn’t work?– mau humor
Cannot verify if it is longer data_password. It is not integer.
– Willian Coqueiro
First thing, your code won’t get to the if? Because you redirect before... have you checked? The password date by your code is just a string, forgot to execute the commands...
– Rodrigo Jarouche
Yes, but when starting this implementation the first time I did it worked, fell in the if. Now it no longer happens and put before the check also does not work
– R.Gasparin
See the $data_password... only has an sql command in it...
– Rodrigo Jarouche
Yes, because that date comes from the bank
– R.Gasparin
To get the data you need to give a mysqli_query and then a mysqli_mysqli_fetch_assoc... http://php.net/manual/en/mysqli-result.fetch-assoc.php
– Rodrigo Jarouche
Okay, thanks for the tip. I’ll fix
– R.Gasparin
Let’s go continue this discussion in chat.
– Rodrigo Jarouche