php - Method to check if username exists in database -
i have method checks if username exists in database:
public function checkusername($username) { global $wpdb; $result = $wpdb->get_row( "select * {$wpdb->prefix}users con_username =".$username); if(!empty($result)){ return false; } } i checking username so:
if(!$users->checkusername($_post['email'])){ $error++; $error_msg[]='email exists!'; } however isnt working telling me every username try exists. dont think have returns written correctly.. ideas??
you not returning if email not found , checkusername return null in case.
$users->checkusername($_post['email']) empty or null.
try -
return empty($result); the function should -
public function checkusername($username) { global $wpdb; $result = $wpdb->get_row( "select * {$wpdb->prefix}users con_username ='".$username."'"); return empty($result); } and check -
if(!$users->checkusername($_post['email'])){ and try implement security input data.
Comments
Post a Comment