调用未定义的函数

调用未定义的函数

问题描述:

我已将一些代码打包到函数中。但是,当我试图让函数来运行我的错误:调用未定义的函数

Fatal error: Call to undefined function qualityCheck()

这里是我的代码:

//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"; 
     } 
    } 

} 

你想带你的函数出的if-else块。你的其他情况应该是这样的

} else { 
    qualityCheck($regname); 
} 
+0

** facepalm **谢谢 – PartisanEntity 2012-02-28 20:50:27