0

I'm doing this project for school and I've come across this issue and I was wondering how I could fix it, username is in varchar, so is password but department is in enum

public function createUserAccount($username,$password,$department){
    if($this->userExists($username)){
        return "USER_ALREADY_EXISTS";
    }
    else{
        $pass_hash = password_hash($password,PASSWORD_BCRYPT,["cost"=>8]);
        $pre_stmt = $this->con->prepare("INSERT INTO `user`(`id`, `username`, `password`, `department`) VALUES (?,?,?,?)");
        $pre_stmt->bind_param("sss",$pass_hash,$username,$department);
        $result = $pre_stmt->execute() or die($this->con->error);
        if($result){
            return $this->con->insert_id;
        }
        else{
            return "some error";
        }
    }

1 Answers1

-1

There are 4 ? in your query, if id column is AUTO_INCREMENT, you can remove it from query like this:

    public function createUserAccount($username,$password,$department){
        if($this->userExists($username)){
            return "USER_ALREADY_EXISTS";
        }
        else{
            $pass_hash = password_hash($password,PASSWORD_BCRYPT,["cost"=>8]);
            $pre_stmt = $this->con->prepare("INSERT INTO `user`(`username`, `password`, `department`) VALUES (?,?,?)");
            $pre_stmt->bind_param("sss", $username, $pass_hash, $department);
            $result = $pre_stmt->execute() or die($this->con->error);
            if($result){
                return $this->con->insert_id;
            }
            else{
                return "some error";
            }
        }