0

我有一个函数可以告诉我电子邮件是否在数据库中。我想知道如果找到它,我怎么能将变量id,name etc与它一起传递给在数据库中找到的特定电子邮件。

function candidateInsert()
{

  if($this->checkEmail($email))
  {
    echo 'found in db';
    echo $email['id'];

  }else{
    echo 'error';
  }
}

function checkEmail($email)
{
     $email = $POST('Email');

    if($email)
    {
        $candemail ="SELECT * FROM {table} WHERE email=?",$email"";

        if(isset($candemail['email']))
        {
                return TRUE;
        } else {
                return FALSE;
        }
    }
}
4

2 回答 2

0

我假设除了布尔值之外,您还想返回 id 和 name。在这种情况下,通过引用传递参数:

function candidateInsert()
{  
      $id = "";
      $name;

  if($this->checkEmail($email, $id, $name))
  {
    echo 'found in db';
    echo $id;
    echo $name;

  }else{
    echo 'error';
  }
}

function checkEmail($email, &$id, &$name)
{
     $email = $POST('Email');

    if($email)
    {
        $candemail ="SELECT * FROM {table} WHERE email=?",$email"";

        if(isset($candemail['email']))
        {
                      $id = $candemail['id'];
                      $name = $candemail['name'];
                return TRUE;
        } else {
                return FALSE;
        }
    }
}

通过在参数的开头添加 &,您可以编辑作为参数传递的变量的内容。

于 2012-09-20T03:10:33.033 回答
0

如果要回显邮件的某些内容,则需要从 CheckMail() 函数返回值,如下所示:

function candidateInsert() {
    $newmail = $this->checkEmail($email);

    if($newmail != FALSE ) {
        echo 'found in db';
        echo $newmail['id'];

     }else{
        echo 'error';
     }
}

function checkEmail($email)
{
    $email = $POST('Email');

    if($email)
    {
        $candemail ="SELECT * FROM {table} WHERE email=?",$email"";
        $result = result($candemail ) // Don't know which sql functions u use

        if(isset($result['email'])) {
            return $result;
        } else {
            return FALSE;
        }
    }
}
于 2012-09-20T03:27:51.813 回答