-3

我试图弄清楚为什么我不断收到此错误:

PHP 致命错误:在第 102 行调用 /home/lear/public_html/storescripts/my_ipn.php 中的未定义函数 uniqueName()

第 102 行是

if ( !uniqueName($username))

require_once 'connect_to_mysql.php';

//now to always get unique username
$username = substr($payer_email, 0, strpos($payer_email, '@'));
if ( ! uniqueName($username))
{
    $username = makeUniqueName($username);
}


//function to check if is the existing username
function isUniqueName($username)
{
    $sql = mysql_query("SELECT username FROM transactions WHERE username='$username'");
    $numRows = mysql_num_rows($sql);
    if ($numRows > 0)
    {
        return false;
    }

    return true;
}


//function to generate new unique username
function makeUniqueName($username)
{
    //serch username string for number at the end
    //regexp makes sure all preceeding zeroes go to first match group
    if (preg_match('/^(\S*?0*)?(\d+?)$/', $username, $match))
    {
        //we got digit from the end of string, just add 1 to the digit
        $username = $match[1] . ($match[2] + 1);
    }
    else
    {
        //no digit at the end of string, just add digit 1 at the end
        $username = $username . 1;
    }

    if (isUniqueName($username))
    {
        return $username;
    }

    return makeUniqueName($username);
}
4

3 回答 3

3

它应该是if ( ! isUniqueName($username))而不是if ( ! uniqueName($username))。注意is前面。

于 2013-07-30T05:15:40.680 回答
1

您正在调用uniqueName,但您的方法被调用isUniqueName

于 2013-07-30T05:15:44.127 回答
0

更改以下内容:

function isUniqueName($username)

function uniqueName($username)

if (isUniqueName($username))
{
    return $username;
}

if (uniqueName($username))
{
    return $username;
}

你在命名函数时搞砸了。

于 2013-07-30T05:18:24.500 回答