This question already has an answer here:
why does mysqli_num_rows
function always returns false in code below?
<?php
if($_POST['submit']){
//to validate the email address
if(!$_POST['email']){
$error.="<br/>Please enter your email";
}else if(!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
$error.="<br/>Please enter a valid email address";
}
// To validate password
if(!$_POST['password']){
$error.="<br/>Please enter a password";
}else{
if(strlen($_POST['password'])<8){
$error.="<br/>Please enter a password with at least 8 characters";
}
if(!preg_match('`[A-Z]`',$_POST['password'])){
$error.="<br/>Please include at least one capital letter in your password";
}
}
if($error){
echo "There were error(s) in your sign up details".$error;
}else{
$link=mysqli_connect("localhost","diary","");
if(mysqli_connect_error()){
die("there is an arror");
}
//$query="insert into `users` (`email`,`number`) values ('asd@asad.com',123)";
$email1=$_POST['email'];
// search for already registered emails
$query="select * from users where email='".mysqli_real_escape_string($link,$email1)."'";
$result = mysqli_query($link, $query);
if (!$result){
die(mysqli_error($link));
}
// And here where errors comes.
$results = mysqli_num_rows($result);
if(!$results){
echo "That email address is already registered";
}else{
echo "dont know";
}
}
}
?>
<form method=post>
<input type="email" name="email" id="email"/>
<input type="password" name="password" />
<input type="submit" name="submit" value="Sign Up">
</form>
</div>