-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 に答える