Extract returns Undefined variable on the detail page

Asked

Viewed 113 times

0

I am with the following variable indefinite error, I am developing a shopping cart using Friendly Url. Everything was going fine until I got to the part of returning all the contents of my product from the database, I’m using the Extract function that in theory was to turn the contents of my database into variables, but that’s not what’s going on, follows the code of my Url class.

public function PegarUrl($url){
     $sql = "SELECT * FROM CADPRO WHERE URL = '$url'";
     $query = sqlsrv_query($this->Conn->Conectar(), $sql) or die( print_r( sqlsrv_errors(), true));
     return $query;    
}

public function UrlAmigavel($url){

        if(isset($_GET['url'])){

            $url = $_GET['url'];
            $pasta = ROOT.DIRECTORY_SEPARATOR;

            if(substr_count($url,'/') > 0){
                $pagina = explode('/', $url);

                if(file_exists($pasta.$pagina[0].'.php')){
                    include_once $pasta.$pagina[0].'.php';

                }else if($this->PegarUrl($pagina[0])){

                    $dadosprod = (array)$this->PegarUrl($pagina[0]);
                    extract($dadosprod);
                    var_dump($dadosprod);
                    include_once $pasta.'detalhe.php';

                }else{

                    include_once $pasta.'error.php';

                }
            }else{
                if(file_exists($pasta.$url.'.php')){

                    include_once $pasta.$url.'.php';

                }if($this->PegarUrl($pasta[0])){

                    $dadosprod = (array)$this->PegarUrl($url);
                    extract($dadosprod);
                    include_once $pasta.'detalhe.php';

                }else{

                    include_once $pasta.'error.php';

                }
            }
        }else{

            include_once 'home.php';

        }    
    }

After doing this on my page details the Url is perfect but when I type the index of the bank that should now be variable since I used the function Extract, they are undefined and do not understand why.

Example: detail page

echo $Titulo_Produto

returns undefined even the index by calling Product Title

  • Isn’t one missing sqlsrv_fetch() that the query result and transfer it into an array?

  • I even did it in the Pegurl method but it hasn’t changed much =(

1 answer

2

I managed to solve, it was missing a fetch_array same.

public function PegarUrl($url){
        $sql = "SELECT * FROM CADPRO WHERE URL = '$url'";
        $query = sqlsrv_query($this->Conn->Conectar(), $sql) or die( print_r( sqlsrv_errors(), true));
        if($query){
            if($std = sqlsrv_fetch_array($query)){
                return $std;
            }  
        }    
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.