I was trying to validate if the username and email in my users table. The validation is working if the username or email is existing in the table it will not be stored but after the submission I only see a white screen in my browser and when I check the server logs I got this error.
PHP Fatal error: Uncaught Error: Call to undefined method
mysqli::mysqli_num_rows() in /var/www/html/NutriCare/signup.php:86\nStack trace:\n#0 {main}\n thrown in /var/www/html/NutriCare/signup.php on line 86
Is there something wrong in my code in database connection?
Here is the code in my config.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "db";
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
Here is the code where I validate the username and email in my signup.php and included the config.php file here
<?php
require 'config.php';
$query = "SELECT username FROM users WHERE username='$username'";
$result = mysqli_query($conn, $query);
$query2 = "SELECT email FROM users WHERE email='$email'";
$result2 = mysqli_query($conn, $query2);
if ($conn->mysqli_num_rows($result) != 0) {
?>
<script>
sweetAlert("Error!", "Username already exist!", "error");
return false;
</script>
<?php
}
if ($conn->mysqli_num_rows($result2) != 0) {
?>
<script>
sweetAlert("Error!", "Email address already exist!", "error");
return false;
</script>
<?php
}
?>
But when I remove this code to validate the email and the username the processing of storing data works with no errors. I had included the $conn->close(); code in the end of the php file I just posted the code I put when I encountered the error. Looking for help. Thanks in advance.