dongmei8071 2018-05-20 17:07
浏览 225
已采纳

警告: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>";
            }
        }
    }
  • 写回答

2条回答 默认 最新

  • dongshuo8756 2018-05-20 17:12
    关注

    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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?