需要帮助才能摆脱PHP代码中限制我在数据库类别中拥有相同条目的限制。(请帮忙)

需要帮助才能摆脱PHP代码中限制我在数据库类别中拥有相同条目的限制。(请帮忙),php,sql,database,Php,Sql,Database,我需要去掉限制我在字段中添加以前条目中相同值的部分。如果条目与数据库中的某个值匹配,我需要删除给我错误消息的部分。有人能帮我吗 <?php class DbOperation { private $conn; //Constructor function __construct() { require_once dirname(__FILE__) . '/Constants.php'; require_once dirna

我需要去掉限制我在字段中添加以前条目中相同值的部分。如果条目与数据库中的某个值匹配,我需要删除给我错误消息的部分。有人能帮我吗

<?php

class DbOperation
{
    private $conn;

    //Constructor
    function __construct()
    {
        require_once dirname(__FILE__) . '/Constants.php';
        require_once dirname(__FILE__) . '/DbConnect.php';
        // opening db connection
        $db = new DbConnect();
        $this->conn = $db->connect();
    }

    //Function to create a new user
    public function createUser($RC, $Date, $Value)
    {
        if (!$this->isUserExist($RC, $Date, $Value)) {
            $password = md5($pass);
            $stmt = $this->conn->prepare("INSERT INTO MyInventory (username, password, email, name, phone) VALUES (?, ?, ?, ?, ?)");
            $stmt->bind_param("sssss", $username, $password, $email, $name, $phone);
            if ($stmt->execute()) {
                return ENTRY_CREATED;
            } else {
                return ENTRY_ALREADY_EXIST;
            }
        } else {
            return ENTRY_ERROR;
        }
    }


    private function isUserExist($username, $email, $phone)
    {
        $stmt = $this->conn->prepare("SELECT id FROM users WHERE username = ? OR email = ? OR phone = ?");
        $stmt->bind_param("sss", $username, $email, $phone);
        $stmt->execute();
        $stmt->store_result();
        return $stmt->num_rows > 0;
    }

调用
createUser
时,它首先通过调用
isUserExist
检查用户是否已经存在(如果数据库中存在具有相同RC的记录)。如果您想允许重复的RC值,只需删除If/else语句,并仅将代码保存在
If
块中。

当您将其传递给此函数时,
$RC
是什么?切勿以明文或使用MD5/SHA1存储密码!仅存储使用PHP创建的密码哈希,然后可以使用进行验证。看看这篇文章:了解更多关于