php error - mysql [duplicate]

-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 error you are giving: Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/u158302715/public_html/bemvindo.php on line 40

    
asked by anonymous 27.05.2016 / 18:30

2 answers

0

The first parameter has to be the MySQL connection you are opening with 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: link

Now look at the code example here in W3Schools: link

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

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

    
27.05.2016 / 18:35
0

and simple in your code is so $sql = mysqli_query("INSERT INTO usuarios (nome, sobrenome, email, senha) VALUES ('$nome', '$sobrenome', '$email', '$senha')"); change so

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

You are using mysqli and the form of writing is as it was written in mysql , so whenever you have a query of mysqli you always have to pass conexao to it '

    
27.05.2016 / 18:56