如何通过相同的 post 检查电子邮件地址或用户名是否有效或存在?

How to check email address or username is valid or exist through same post?

如何检查电子邮件地址或用户名是否有效或是否存在 post?

HTML

 <form action="/index" method="post">
             <input name="post" type="text" value="Username or Email" />
             <input name="submit" name="send" value="Submit" />
        </form>

PHP

  public function index($post) 
        {
            $results = $this->db->where('username', $post)
                                ->where('email', $post)
                                ->get('users');

            if($results->num_rows() > 0)
            {
              //The user has an email or username
              echo "valid";
            } else {
              echo "Invalid";
            }
        }

将第二个 ->where 子句更改为 ->or_where

public function index($post) 
    {
        $results = $this->db->where('username', $post)
                            ->or_where('email', $post)
                            ->get('users');

        if($results->num_rows() > 0)
        {
          //The user has an email or username
          echo "valid";
        } else {
          echo "Invalid";
        }
    }

查看此文档以供参考Active Record : CodeIgniter

替换HTML
值 -> 占位符

替换 Codeigniter
其中 -> or_where 修复并添加评论。

<form action="/index" method="post">
   <input name="post" type="text" placeholder="Username or Email" />
   <input name="submit" name="send" placeholder="Submit" />
</form>

public function index($post) 
{
    $results = $this->db->where('username', $post)
                        ->or_where('email', $post) //where[or] : on the condition
                        ->get('users');

    if($results->num_rows() > 0) //The user has an email or username
    {
        echo "valid";
    }
    else
    {
        echo "Invalid";
    }
}