-3

我有一个检查功能:

function checkCandidateEmail($email)
    {
         $email = $_POST;

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

            return $canEmailCheck;
        }
    }

我已经开始创建一个函数,但我得到 NULL

4

2 回答 2

2
function checkCandidateEmail($email)
    {
         $email = $_POST; // being immediately overwritten - redundant argument. 

        if($email) // Since $email isn't an optional argument, you'll get a PHP warning if it is missing, making this check confusing.
        {
            $candemail = (SQL); // Evaluating a constant? this will be bool 
            if(isset($candemail['email'])) // Since $candemail is a bool and not an array, this will never return true
            {
              return TRUE;
            } else {
              return FALSE;
            }  // this entire if/else block can be simplified to this: return (isset($candemail['email']));

            return $canEmailCheck; // this is an undefined variable and will never get returned anyway because of the above return statements.
        }
    }
于 2012-09-19T23:07:06.827 回答
1

下次请详细说明您的问题。如果 $_POST 与 SQL 查询或参数与 SQL 查询一起传递,我不确定您尝试比较什么。我假设前者。

如果来自该 SQL 表行的电子邮件等于提交的电子邮件,则返回 TRUE。否则,返回 FALSE。真正的简化版。现在它还会检查用户是否提供了电子邮件:

function checkCandidateEmail()
    {
    if (!$_POST['email']) echo "Error, please provide an email";
    else
      {
      $candemail = (SQL);   // Return a row from a query
      return $candemail['email'] == $_POST['email'];
      }
    }

如果传递了参数,则将其与数据库进行比较。如果没有通过,将提交的 $_POST['email'] 与数据库进行比较。

function checkCandidateEmail($email=null)
    {
    $candemail = (SQL);   // Return a row from a query
    if (!$email) $email = $_POST['email'];
    return $candemail['email'] == $email;
    }

SQL注意:在这两种情况下,您都必须根据您的数据库替换正确的字符串和函数。

注意 2:确保您的查询返回一封电子邮件,因为此简单代码不会检查两个字符串是否为空。

于 2012-09-19T23:33:19.713 回答