2016-10-12 3 views
0

メールアドレスまたはユーザー名を確認する方法は有効か、同じ投稿を通じて存在していますか?電子メールアドレスまたはユーザー名を確認する方法は有効か、同じ投稿を通じて存在していますか?

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"; 
      } 
     } 

答えて

1

変更秒->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

+0

ありがとうございます。これに答えることはできますかhttp://stackoverflow.com/questions/40238671/ajax-upload-not-working-codeigniter? – Mehur

0

ためのメンターは、HTML
値を置き換える - > or_where固定され、コメントを追加 - >プレースホルダ

はCodeIgniterの
を交換してください。

<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"; 
    } 
} 
関連する問題