Problem with MYSQL + PHP Database

Asked

Viewed 59 times

0

When running this page, returns me the following error.

Fatal error: Call to Undefined Function query() in C: Program Files Vertrigoserv www admin.php on line 6

My Php Code.

<?php

include("conexao.php");

$consulta = "SELECT * FROM snaps";
$con = $mysqli=query($consulta) or die($mysqli=error);
?>

<html>
    <head>
        <meta charset="utf8">
    </head>
    <body>
        <table>
            <tr>
                <td>Codigo</td>
                <td>Nome</td>
                <td>SnapChat</td>
                <td>Email</td>
                <td>Data de Cadastro</td>
            </tr>
            <?php while($dado = $con->fetch_array()){?>
            <tr>
                <td><?php echo $dado["id"]; ?></td>
                <td><?php echo $dado["nome"]; ?></td>
                <td><?php echo $dado["snapc"]; ?></td>
                <td><?php echo $dado["email"]; ?></td>
                <td><?php echo $dado["created"]; ?></td>
            </tr>
            <?php }?>
        </table>
    </body>
</html>

And this is my Connexion.php

<?php
$servidor = "localhost";
$usuario = "root";
$senha = "vertrigo";
$dbname = "snapsje";

//Criar a conexao
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname);
  • You realize what you’re doing $mysqli=query instead of $mysqli->query? In $mysqli=error same thing. Typo. By the way, the object $mysqli nor exists in your code. You have set the connection to the database at $conn.

  • Yes, I changed $mysqli->query to $mysqli=query, because when I leave $mysqli->query, it returns this - Notice: Undefined variable: mysqli in

  • Yeah, I commented on that too.

1 answer

0


What are you doing here $mysqli=query() is instantiating a variable called mysql and assigning the returned function value query(), which I believe does not exist in your program.

To fix try this way:

$con = $conn->query($consulta) or die($conn->error);

Or that:

$con = mysqli_query($conn, $consulta) or die(mysqli_error);
  • Solved, thank you very much !

  • If the answer is right, please mark as correct.

Browser other questions tagged

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