Hi, I been getting an error on my registration form. I am not understanding what I need to do in my case. I know this question was solved elsewhere but it isn't related to my case.
the PHP error I get is Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in
line 19 & 29.
<?php
require('server.php');
// If the values are posted, insert them into the database.
if (isset($POST['username']) && isset($POST['password']))
{
$username = mysqli_real_escape_string($connection, $POST['username']);
$email = mysqli_real_escape_string($connection, $POST['email']);
$password= $_POST['password'];
$hashed = hash('sha1', $password);
$Confirmpassword = $_POST['Confirmpassword'];
if($password == $Confirmpassword)
{
//Checking username with database
$failmsg ="";
$usernamesql = "SELECT * FROM `user` WHERE username='$username'";
$usernameres = mysqli_query($connection, $usernamesql);
$count = mysqli_num_rows($usernameres);
if($count == 1)
{
$failmsg .="Username Already Exists";
}
//Checking Email with database
$emailsql = "SELECT * FROM `user` WHERE email='$email'";
$emailres = mysqli_query($connection, $emailsql);
$emailcount = mysqli_num_rows($emailres);
if($emailcount == 1)
{
$failmsg .="Email Already Exists";
}
//SQL entering data into Database with validation
$sql = "INSERT INTO `usercontrol` (username, password, email) VALUES ('$username', '$hashed', '$email')";
$result = mysqli_query($connection, $sql);
if($result)
{
$successmsg = "User Created Successfully.";
}
else
{
$failmsg = "User Registration Failed";
}
}
else
{
$failmsg = "Password doesn't Match";
}
}
?>