1
Good afternoon, I’m having a big problem where I can’t get the password in the system. What is bugging me is that it seems that sqlsrv_fetch_array works differently from mysql_fetch_array, I have a code like this using Mysql and works well but SQL Server is not, so I came here asking for help on this system.
public function alterarsenha($Nome, $Senha, $Novasenha, $Confirnovasenha){
$sql = "SELECT SENHA FROM CADPES WHERE NOME = '$Nome'";
$query = sqlsrv_query($this->Conn->Conectar(), $sql) or die( print_r( sqlsrv_errors(), true));
$senhabanco = '';
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
$senhabanco = $row['SENHA'];
}
if(($Senhanova == "") OR ($Confirsenha) == "" ){
echo "Insira a nova senha!";
//header('location:index.php');
}else{
if($Senha != $senhabanco){
echo "Nome ou senha inválido!";
}else{
if($Novasenha != $Confirnovasenha){
echo "Campos da nova senha não conferem!";
}else{
$upd = "UPDATE CADPES SET SENHA = '$Novasenha' WHERE NOME = '$NOME'";
$upd_query = sqlsrv_query($this->Conn->Conectar(), $sql);
if($upd_query){
echo "Senha alterado com sucesso";
//header('location:index.php');
}else{
echo "Ocorreu um erro na trocra de Números";
//header('location:index.php');
}
}
}
}
I’m stuck here !
if($Senha != $senhabanco){
echo "Nome ou senha inválido!";
}else{
The problem is that the $senhabanco variable always has the NULL value even though I did the while. And I’ve even tried to change the place key put at the end but results in another mistake.
Tried to print the values of the two variables with
var_dump()/print_r()
?– rray
yes, inside while not printed anything, outside it prints null!
– Alison Paulo