【问题标题】:Cannot understand this fatal error. Can somebody check?无法理解这个致命错误。有人可以检查吗?
【发布时间】:2022-06-15 07:52:41
【问题描述】:

我正在为登录系统做一个教程,但我总是得到这个错误: “致命错误:未捕获的错误:调用 C:\xampp\htdocs\php_course\projects\includes\register-inc.php:25 中的未定义函数 mysqli_stmt__prepare() 堆栈跟踪:#0 {main} 在 C:\xampp\ 中抛出htdocs\php_course\projects\includes\register-inc.php 在第 25 行" 这是我的代码

<?php
    //Add database connection
    require 'database.php';

    $username = $_POST['username'];
    $password = $_POST['password'];
    $confirmPass = $_POST['confirmPassword'];

    if (empty($username) || empty($password) || empty($confirmPass)){
        //redirects user to same page       
        header("Location: ../register.php?error=emptyfields&username=".$username);
        exit();
    }else if (!preg_match("/^[a-zA-Z0-9]*/",$username)) {
        header("Location: ../register.php?error=invalidusername&username=".$username);
        exit();
    } else if ($password !== $confirmPass){
        header("Location: ../register.php?error=passwordsdonotmatch&username=".$username);
        exit();
    }else {
        //PREPARED STATEMENTS
        $sql = "SELECT username FROM users WHERE username = ? ";
        $stmt = mysqli_stmt_init($conn);
        if(!mysqli_stmt__prepare($stmt, $sql)){
            header("Location: ../register.php?error=sqlerror");
        exit();
        }else{
            //send data inputed by the user to the database
            mysqli_stmt_bind_param($stmt, "ss", $username);
            mysqli_stmt_execute($stmt);
            //With below function we get back data from database to see if username exists
            mysqli_stmt_store_result($stmt);
            $rowCount = mysqli_stmt_num_rows($stmt);

            if($rowCount > 0){
                header("Location: ../register.php?error=usernametaken");
            } else {
                $sql = "INSERT INTO  userS (username, password) VALUES (?, ?)";
                //Initiate database connection
                $stmt = mysqli_stmt_init($conn);
                if(!mysqli_stmt__prepare($stmt, $sql)){
                    header("Location: ../register.php?error=sqlerror");
                exit();
                }else {
                    /*Hashing turns your password into a short string of letters 
                    and/or numbers using an encryption algorithm. we will use bcrypt 
                    for that now.Bcrypt is a library that hashes passwords.*/
                    $hashedPass = password_hash($password, PASSWORD_DEFAULT);

                    mysqli_stmt_bind_param($stmt, "ss", $username, $hashedPass);
                    mysqli_stmt_execute($stmt);
                    //redirect
                    header("Location: ../register.php?success=register");
                    exit();
                }
            }
        }
    }
    //closing the sql statement  
    mysqli_stmt_close($stmt);
    //Shut down database connection
    mysqli_close($conn);  
}


?>```

【问题讨论】:

  • mysqli_stmt__prepare 中有两个下划线。应该是mysqli_stmt_prepare

标签: php mysql fatal-error


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-05
  • 2016-07-09
  • 1970-01-01
  • 2012-04-19
  • 1970-01-01
  • 2019-09-23
相关资源
最近更新 更多