mysqli_stmt :: bind_param():第34行上的已准备语句中的变量数量与参数数量不匹配

时间:2019-07-05 09:11:56

标签: php mysql mysqli

因此,我正在学习PHP,到目前为止,我已经连接到数据库,并且可以完全正常工作,如果我编写它将出现在数据库中的表格。但是,它仍然给我这个错误

我尝试了很多事情,我的代码也看起来与其他人非常相似,但是我没有找到任何帮助。

<?php
   $username = $_POST["username"];
   $email = $_POST["email"];
   $password = $_POST["password"];

   if (!empty($username) || !empty($email) || !empty($password)) {
     $host = "localhost";
     $dbUsername = "root";
     $dbpassword = "";
     $dbname = "login_project_php";

     //create connection
     $conn = new mysqli($host, $dbUsername, $dbpassword, $dbname);
     if (mysqli_connect_error()) {
        die('connect error('. mysqli_connnect_errorno() . ')'. mysqli_connect_error());
     } else {
         $SELECT = "SELECT email from users where email = ? limit 1";
         $INSERT = "INSERT INTO `users`( `username`, `email`, `password`) VALUES ( ?, ?, ?)";

         //prepare statment
         $stmt = $conn->prepare($SELECT);
         $stmt->bind_param("sss", $username, $email , $password);
         $stmt->execute();
         $stmt->bind_result($email);
         $stmt->store_result();
         $rnum = $stmt->num_rows;

         if ($rnum==0) {
           $stmt->close();

           $stmt = $conn->prepare($INSERT);
           $stmt->bind_param("sss", $username, $email, $password);
           $stmt->execute();
           echo "User created peace";
         } else {
           echo "Someone already registerd with this email ";
         }
         $stmt->close();
         $conn->close();
     }
   } else {
     echo "<p> all fields are required </p>";
     die();
   }
      ?>

我希望它能在没有警告的情况下工作,但我真的不知道

0 个答案:

没有答案