-3

I am having an issue trying to check whether user email is available or no in database so, that i can send him ...an email with his password .....am stuck in if statement that count the number of rows in query result........hoping positive reply ....

 if(isset($_POST['email']))

{
$email=$_POST['email'];
$query="SELECT  email FROM signup WHERE email='" .$email." '   ";
$result=mysqli_query($connect,$query) ;
  $num_rows = mysqli_num_rows($result);
if(mysqli_num_rows($result)==0){
echo "user exist";
}


}
alex
  • 1
  • 3
    Shouldn't it be `mysqli_num_rows($result) !=0` . – sarveshseri Feb 03 '15 at 16:19
  • 4
    you are vulnerable to [sql injection attacks](http://bobby-tables.com) and have absolutely NO error handling. You're simply assuming nothing could ever go wrong. And as @Sarvesh pointed out, your logic is wrong anyways. – Marc B Feb 03 '15 at 16:20

1 Answers1

2

Your if statement is wrong, if the user does exists you'll have at least one line in the result set. You can use :

if(mysqli_num_rows($result)>0){ //...

or

if(mysqli_num_rows($result)!=0){ //...
NeoPix
  • 433
  • 5
  • 14
  • thanks ....ur answer didn't work ...i hv already tried it ..i just want to know if the email that is entered by user using an html form ...does exist or no... – alex Feb 03 '15 at 16:36