php – Erro “expects parameter 1 to be mysqli, string given in”


I'm creating an insert form for registration, but when I click on the button it's giving me an error:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp64\www\Beauty and Harmony Project\Beauty and Harmony – site\php\cadastro.php on line 25

What is it getting?


    <title>cadastro concluido</title>



$nome = $_POST['nome'];
$ende = $_POST['endereco'];
$tel = $_POST['telefone'];
$comple = $_POST['complemento'];
$login = $_POST['login'];
$senha = $_POST['senha'];
$mail = $_POST['emails'];
$nume = $_POST['numero'];

$sql = "INSERT INTO usuario(nome, telefone, endereco, numero, complemento, email, login, senha) VALUES('$nome', '$tel', '$ende', '$nume', '$comple', '$mail', '$login', '$senha')";

        $result = mysqli_query($bd, $sql) or die ('Error querying database.');






$host = "localhost";
$usuario = "root";
$senha = "";

$mysqli = new mysqli($host, $usuario, $senha, $bd);

if($mysqli -> connect_errno) {
    echo "Falha na conexão: (".$mysqli->connect_errno.") ".$mysqli->connect_error;


line 25:

 $result = mysqli_query($bd, $sql) or die ('Error querying database.');

can anybody help me? Thanks…


Virtually all mysqli functions use the database connection "link" as the first parameter.

You do:


And try to use

$result = mysqli_query($bd, $sql);

The 1st parameter must be the connection, not the DB name.

The correct thing would be:

$result = mysqli_query( $mysqli, $sql );

Improvement suggestion:

In order not to make a mess, I suggest changing the link/connection name to $con or $link , which are very common in documentation and examples:

$link = new mysqli($host, $usuario, $senha, $bd);

and then:

$result = mysqli_query( $link, $sql );
Scroll to Top