Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7605389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:09:20+00:00 2026-05-31T00:09:20+00:00

I have packed some of my code into a function. But when I try

  • 0

I have packed some of my code into a function. But when I try to get the function to run I an error:

Fatal error: Call to undefined function qualityCheck()

Here is my code:

//include our db file to make a connection to the mysql db
require_once 'db.php';

//our form is providing us with the value of the input field called username through the GET method
//we store it in the variable $regname 
$regname = htmlspecialchars($_GET['username']);
$regmail = htmlspecialchars($_GET['email']);

if (strlen($regname)<5) {
        echo "Username must be at least 5 characters";
} else {

    qualityCheck($regname);

    function qualityCheck($qcName) {

        //rules for username
        $pattern = "^[a-z0-9_-]{5,20}$";

        //first we check that the username fits the rules
        if (preg_match($pattern, $qcName)) {

            //if quality check is pass, wemake a mysql db query and select all rows from table users with the same username as the one
            //that is intended to be used by the registree if the mysql query returns a value then it means
            //that the username exists already and so we must echo an error message back to the form

                $result = mysqli_query($dblink, "SELECT * FROM users WHERE `username` = '$regname'") 
                or die(mysqli_error($dblink));

                if ((mysqli_affected_rows($dblink)) > 0 ) {
                    echo "Username taken already";
                } else {
                    echo "Username available";
                    }
        } else {

            //if username fails the quality check
            echo "Username must consist of A-Z and 0-9";
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:09:22+00:00Added an answer on May 31, 2026 at 12:09 am

    You want to bring your function out of the if-else block. Your else case should just look like this

    } else { 
      qualityCheck($regname);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a java application and have packed it into an executable jar
I have created a java application and packed it into a jar file on
HI I have created a ActiveX componed and packed into a cab file 1)
I have a problem with some simple code. The photo's, either picked or taken
At the risk of appearing a dinosaur, I have some old C++ code, compiled
I have some numbers, encoded in byte array using variable-length code. Actually it's GIF89a
We have some code that is making use of the new postMessage functionality in
So I ran into a situation today where some production code was failing precisely
I have the following record definition E3Vector3T = packed record public x: E3FloatT; y:
Say I have a fairly hefty JavaScript file, packed down to roughly 100kb or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.