将值插入表格

时间:2019-11-04 07:45:10

标签: database sql-insert

我设法为用户创建数据库和表,但是当我执行sql语句插入值时,什么也没插入

我试图在我的sql中运行查询,但是可以运行,但是当我运行php脚本时却无法运行

///在插入数据库之前检查输入错误     if(空($ username_err)&&空($ email_err)&&空($ verified_err)&&空($ token_err)&&空($ password_err)&&空($ confirm_password_err)){

    // Prepare an insert statement
    $sql = "INSERT INTO users (username, email, verified, token, password) VALUES (:username, :email, :verified, :token, :password)";

    if($stmt = $pdo->prepare($sql)){
        // Bind variables to the prepared statement as parameters
        $stmt->bindParam(":username", $param_username, PDO::PARAM_STR);
        $stmt->bindParam(":email", $param_email, PDO::PARAM_STR);
        $stmt->bindParam(":verified", $param_verified, PDO::PARAM_STR);
        $stmt->bindParam(":token", $param_token, PDO::PARAM_STR);
        $stmt->bindParam(":password", $param_password, PDO::PARAM_STR);

        // Set parameters
        $param_username = $username;
        $param_email = $email;
        $param_password = password_hash($password, PASSWORD_DEFAULT);// Creates a password hash
        $param_token = bin2hex(random_bytes(50));
        $param_verified = false;

        // Attempt to execute the prepared statement
        if($stmt->execute()){
            // Redirect to login page
            header("location: login.php");
        } else{
            echo "Something went wrong. Please try again later.";
        }
    }

    // Close statement
    unset($stmt);
}

预期结果是将数据插入到用户表中

0 个答案:

没有答案