function username_exists($username){
                        global $db;
                        $sql = "SELECT 'username' FROM users WHERE 'username' = '$username'";
                        $result = mysqli_query($db, $sql);
                        confirmquery( $result );

                         if (mysqli_num_rows($result) > 0) {
                           return true;
                         }else {
                           return false;
                         }
                    }
                    if(username_exists($username)){
                            $error['username'] = 'Username already exists';
                          }

Try

SELECT `username` FROM users WHERE `username` = '$username'

instead of

SELECT 'username' FROM users WHERE 'username' = '$username'

(backticks instead of single quotes)

And be careful of SQL injection attacks! Always escape any variables containing user-entered data before including them in your SQL queries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.