PHP - mysqli :Count if database returned any record -
i trying query database on basis of given username. if username matches want return true , following code
<?php function user_exists($username){ $username= sanetize($username); $query= mysqli_query($connect, "select count('user_id') users username= '$username'"); if(mysqli_num_rows($query)>0){ return true; } }
problem when try not show result , alex dummy entry in db should not echo user exists ?
if(user_exists('alex')){ echo 'exists'; }
this may work after removing single quotes column name ‛user_id‛
$query= mysqli_query($connect, "select count(user_id) users username= '$username'");
further more http://www.w3schools.com/php/func_mysqli_num_rows.asp
edit: first of make sure $connect available function scope before anything
$query = mysqli_query($connect, "select count(*) `users` username='".$username."'"); if(mysqli_num_rows($query) > 0){ echo "user exists"; }else{ // if (!mysqli_query($dbl,$query)) { die('error: ' . mysqli_error($dbl)); } }
Comments
Post a Comment