如何检查电子邮件地址或用户名是有效的或存在通过相同的职位? [英] How to check email address or username is valid or exist through same post?

查看:121
本文介绍了如何检查电子邮件地址或用户名是有效的或存在通过相同的职位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to check email address or username is valid or exist through same 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";
            }
        }


推荐答案

更改第二个 - >其中子句至 - > 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";
        }
    }

请参阅此文档以供参考活动记录:CodeIgniter

Take a look at this document for reference Active Record : CodeIgniter

这篇关于如何检查电子邮件地址或用户名是有效的或存在通过相同的职位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆