Error of php --> mysql

Asked

Viewed 76 times

-1

$nome=$_POST['nome'];

$sobrenome=$_POST['sobrenome'];

$email=$_POST['email'];

$senha=$_POST['senha'];

$sql = mysqli_query("INSERT INTO usuarios (nome, sobrenome, email, senha)
VALUES ('$nome', '$sobrenome', '$email', '$senha')");

The mistake you’re making: Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/u158302715/public_html/bemvindo.php on line 40

2 answers

0

The first parameter has to be the Mysql connection you are opening by mysqli_connect(). For you to use only the query you would have to use the static mode of the function with mysqli::query().

Take a look at the documentation for this function in php.net: http://php.net/manual/en/mysqli.query.php

Now see the code example here at W3schools: http://www.w3schools.com/php/func_mysqli_query.asp

Note the line: $con=mysqli_connect("localhost","my_user","my_password","my_db");

And now see that $con is passed as parameter: mysqli_query($con,"SELECT * FROM Persons");

  • thanks, but in case the connection is already established, but when it arrives in mysqli_query gives this error

  • Because you are not passing the parameter to the function you called here: mysqli_query("INSERT INTO usuarios (nome, sobrenome, email, senha)
VALUES ('$nome', '$sobrenome', '$email', '$senha')"); it would have to be something like mysqli_query($con, "INSERT INTO usuarios (nome, sobrenome, email, senha)
VALUES ('$nome', '$sobrenome', '$email', '$senha')");

0

and simple in your code this way $sql = mysqli_query("INSERT INTO usuarios (nome, sobrenome, email, senha) VALUES ('$nome', '$sobrenome', '$email', '$senha')"); exchange for this

$sql = mysqli_query($variavel de conexao, "INSERT INTO usuarios (nome, sobrenome, email, senha) VALUES ('$nome', '$sobrenome', '$email', '$senha')");

you’re using mysqli and the form of writing is as it was written before in mysql, so whenever you have a query of mysqli will always have to pass the conexao in it`

Browser other questions tagged

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