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 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的