Error changing password in login system with PHP SQL Server

1

Good afternoon, I'm having a big problem where I can not change the password on the system. What is driving me is that it seems that sqlsrv_fetch_array works differently from mysql_fetch_array, I have a code like that using MySQL and it works fine but in SQL Server it is not, so I came here asking for help on that 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{

Do not leave this condition the problem is that the variable $ senhabanco always has the value NULL even though I have done the while. And even tried to change the place key put at the end but it results in another error.

    
asked by anonymous 06.10.2016 / 22:44

1 answer

0

After a few hours' hunch, I found the 3 errors that made the system not spin.

1st in the while, 2nd query had passed the wrong parameter and lastly in sqlsrv_query I had placed $ sql before.

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)){

        $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(), $upd);

                    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');
                    }
            }
        }   
}
    
07.10.2016 / 14:47