警告:mysqli_query()需要至少2个参数,1在[...]中给出

  • Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\Qumanegistar.php on line 11
  • Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\Qumanegistar.php on line 12
  • Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\Qumanegistar.php on line 23
  • Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\Qumanegistar.php on line 23

Code:

    if (isset($_POST['criar'])) {
        $nome = $_POST['nome'];
        $apelido = $_POST['apelido'];
        $email = $_POST['email'];
        $pass = $_POST['pass'];
        $data = date("Y/m/d");

        $email_check = mysqli_query("SELECT email FROM users WHERE email='$email'");
        $do_email_check = mysqli_num_rows($email_check);
        if ($do_email_check >= 1) {
            echo '<h3>Este email já está registado, faça o login, caso seja o seu, entre <a href="login.php">aqui!</a></h3>';
        }elseif ($nome == '' OR strlen($nome)<3) {
            echo '<h3>Escreva seu nome corretamente!</h3>';
        }elseif ($email == '' OR strlen($email)<10) {
            echo '<h3>Escreva seu email corretamente!</h3>';
        }elseif ($pass == '' OR strlen($pass)<8) {
            echo '<h3>Escreva a palavra-passe corretamente, deve possuir no mínino 8 caracteres!</h3>';
        }else{
            $query = "INSERT INTO users (`nome`,`apelido`,`email`,`password`,`data`) VALUES ('$nome','$apelido','$email','$pass','$data')";
            $data = mysqli_query($query) or die(mysqli_error());
            if ($data) {
                setcookie("login",$email);
                header("Location: ./");
            }else{
                echo "<h3>Desculpe, houve um erro ao registar-se...</h3>";
            }
        }
    }

The errors are self-explanatory, mysqli_query requires 2 parameters - the documentation is available here: https://php.net/mysqli_query

As per the docs, the first parameter is your database connection created through mysqli_connect.

Your could should read similar to:

$db = mysqli_connect(..);

// ..

$email_check = mysqli_query($db, "SELECT email FROM users WHERE email='$email'");

Also, your code is vulnerable to SQL injection, you should consider using parameters in your query with code such as:

if ($stmt = mysqli_prepare($db, "SELECT email FROM users WHERE email = ?"))
{
    mysqli_stmt_bind_param($stmt, "s", $email);

    mysqli_stmt_execute($stmt);

    $email_check = mysqli_stmt_num_rows($stmt);
}

TL;DR You need to supply the connection to query in the mysqli_query function.

I suppose you are asking why you are getting these error messages. The first message specifiec that you need to have two parameters in the mysqli_query call. The first is the connection to your server, the second is the query itself.

Here is an example from https://www.w3schools.com/php/func_mysqli_query.asp

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
// Perform queries
mysqli_query($con,"SELECT * FROM Persons");
mysqli_query($con,"INSERT INTO Persons (FirstName,LastName,Age)
VALUES ('Glenn','Quagmire',33)");
mysqli_close($con);
?>

The second error message is because the $email_check will become null when the msqli_query call fails, therefore making msqli_num_rows fail. Note that you will obviously have to change all myqsli_query calls. Here is a link to the manual if you want to read more about the call, http://php.net/manual/en/mysqli.query.php.