I have small php web service and I tested it locally and it works. When I uploaded it to bluehost server I get NULL as a result from calling mysqli_query
$con = connect();
$userName = mysqli_real_escape_string($con, $userName);
$email = mysqli_real_escape_string($con, $email);
$query1 = "select * from `users` where `user_name` = '$userName'";
$res1 = mysqli_query($con, $query1);
//var_dump($res1) prints NULL
if ($res1) {
$count = mysqli_num_rows($res1);
if ($count == 0) {
$query2 = "select * from `users` where `email` = '$email'";
$res2 = mysqli_query($con, $query2);
if ($res2) {
$count2 = mysqli_num_rows($res2);
if ($count2 == 0) {
return 0; //not found before
} else {
return 2; //Email already exists
}
}
} else {
return 1; //user name already exists
}
} else {
return -1; //Database Error; // always resturned
}
Edit 1: //Code to connect to database function connect() {
$con = mysqli_connect("localhost", "user", "pass", "db");
if (mysqli_connect_errno()) {
return 0;
} else {
return $con;
}
}
EDIT 2:
If I added mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
in the first line at connect() method, I got nothing at all, even the -1 return is not there.