2012-02-28 7 views
1

함수에 일부 코드를 압축했습니다. 내가 얻으려고하지만 기능은 I에게 오류를 실행합니다 : 당신은 경우 - 다른 블록에서 당신의 기능을 가지고 싶어정의되지 않은 함수를 호출하십시오.

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

} 

답변

2

:

Fatal error: Call to undefined function qualityCheck()

여기 내 코드입니다. 다른 케이스는 다음과 같이 표시되어야합니다.

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

** facepalm ** 감사합니다. – PartisanEntity

관련 문제