line 35 : if (mysqli_num_rows($usernameQuery) > 0) {
echo "Username is already used: Pick another username";
I've written a registration code but upon finishing and i was brought the following error :
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\wamp64\www\loginregister\register.php on line 35
What I have tried:
<?php
require "conn.php";
$username = $_POST["$username"];
$email = $_POST["$email"];
$password = $_POST["$pass"];
$mobile = $_POST["$mobile"];
$gender = $_POST["$gender"];
$isValidEmail = filter_var($email,FILTER_VALIDATE_EMAIL);
if ($conn){
if (strlen($password) < 6 || strlen($password) > 40) {
echo "password should be more than 6 characters";
}elseif ($isValidEmail === false ) {
echo "Please write a valid email";
}
else {
$sqlCheckUsername = "SELECT * FROM 'users_table' WHERE 'username' LIKE '$username' ";
$usernameQuery = mysqli_query($conn,$sqlCheckUsername);
$sqlCheckEmail = "SELECT * FROM 'users_table' WHERE 'email' LIKE '$email' ";
$usernameQuery = mysqli_query($conn,$sqlCheckEmail);
if (mysqli_num_rows($usernameQuery) > 0) {
echo "Username is already used: Pick another username";
}elseif (mysqli_num_rows($usernameQuery) > 0) {
echo "email is already registered";
}
else {
$sql_register = "INSERT INTO 'users_table'(`username`,`email`,`password`,`mobile`,`gender`) VALUES ('$username','$email','$password','$mobile','$gender')";
}
if (mysqli_query($conn,$sql_register)) {
echo "Registration Successful";
}
else {
echo "Failed to Register";
}
}
}
else {
echo "connection error: Check Your Connection and Try again";
}
?>