php - How to use 'or' inside mysqli prepare statement query -


i'm new mysqli prepare statement , surprised find out || doesn't work expected in mysqli prepare statement query. have function check whether user registered, , evaluation should based upon unique row id , email address.besides, since id column , email column of different type, int(11) , varchar respectively, assumed it's going have trouble using bind_param because different data type

public function checkuserregistered($iden){  //the iden can either id or email address             $stmt = $this->connection->prepare("select `id` `$this->table_name` (`email`= ?  || `id`= ?) limit 1 ");             $stmt->bind_param('s',$iden); // s or ?             if($stmt->execute()){                 $result = $stmt->get_result();                 if($result->num_rows ==1){                     $stmt->close();                     return true;                 }else{                     return false;                 }             }         } 

what right way of doing this, have use separate functions instead?

you need bind 2 params this:

$stmt->bind_param('si',$iden, $iden); 

as have set 2 '?'.

s means string, means integer, b blob , d double.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -