Error in row mysql_fetch_array

Asked

Viewed 172 times

0

This is an information seeker from universities, my TCC.
This is the mistake:
inserir a descrição da imagem aqui

$mysqlli = new mysqli($servidor,$user,$senha,$banco);

if(mysqli_connect_errno()) trigger_error(mysqli_connect_error());
else
echo "sucesso";

//@mysql_select_db("faculdadesbd",$mysqlli);

?> Unigle body{ font-family:Verdana, Geneva, sans-Rif; color:#333; font-size:12px; }




<?php
    if(isset($_POST['botao'])){
        $busca = $_POST['busca'];

        $busca_dividida = explode(' ',$busca);
        $quant = count($busca_dividida);

        for($i=0;$i<$quant;$i++){
            $pesquisa = $busca_dividida[$i];

            $sql = ("SELECT * FROM busca WHERE nome_fac LIKE '%$.pesquisa.%'");
            $query = $mysqlli->query($sql);
            while($linha = mysql_fetch_array($sql)){
                $nome_fac = $linha['Nome'];
                $data_vest = $linha['Data Vestibular'];
                $data_taxa = $linha['Data Taxa'];
                $nota_corte = $linha['Nota de corte'];
                $nota_enem = $linha['Nota ENEM'];

                echo"
                    <div class='resultado'>
                        <h2>".$nome_fac."</h2>
                        <p>".$data_vest."</p>
                        <p>".$data_taxa."</p>
                        <p>".$nota_corte."</p>
                        <p>".$nota_enem."</p>
                    </div>
                    ";
        }
    }
    }
?>

  • 1

    Help us help you. What the error says?

  • In the other ask was mysql_fetch_array($sql) stay tuned to use only a connection driver with the database preferably mysqli. See how the site works on tour, how to ask and don’t forget to debug ;)

  • I mistook it when pasting the code only.

  • Place: $query->fetch_assoc()no lugar demysql_fetch_array($sql)`

  • The following errors occurred when replacing mysql_fetch_array($sql) with $query->fetch_assoc()`: http://i.imgur.com/Qvblwv6.png? 1

  • In the question code there is no variable called query. Check the variable names if you need to edit the question and enter the correct code.

  • The query variable is $query. I’m sorry, I posted the error in Portuguese, here it is in English if it helps: http://i.imgur.com/Glrstal.png

  • query() returns false when the query has an error, thus displays the error of the database: $query = $mysqlii->query($sql); if(!$query){ echo $mysqlii->error;}

Show 3 more comments

1 answer

1


It seems to be just a typo, your connection object is $mysqlli and at the time of calling the method query() you call a variable that does not exist $mysqli. To correct change the call from:

$query = $mysqli->query($sql);

for:

$query = $mysqlli->query($sql);

When a blank screen is displayed, this means two things an error has occurred and the error display has been hidden (usually for security reasons). In such case it is possible to overwrite this setting errors, the following lines should be at the beginning of your file.

 <?php
 ini_set('display_errors', true);
 error_reporting(E_ALL);

 echo '...';

The line below can be removed, and avoid using @ because it hides errors, which makes it more difficult to fix the bug.

@mysql_select_db("faculdadesbd",$mysqlli);

Browser other questions tagged

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