Beginner here, I am trying to make a call from the PhoneGap application to a web server using XAMPP local host for a school assignment. I have a working login.php file from one of the previous projects. However, once transferred to the new project, Eclipse would not run the PHP codes and thus, the whole project, displaying the error as shown above: “Fatal error: Call to a member function fetch_array() on null”.
The differences between the project now and the ones before was where I placed the PHP files. Since I no longer have a microsoft azure subscription, I have switched to local host XAMPP. As a result, also changing my php file location from http://example.cloudapp/login.php to the same folder where I have my html files, to htcdocs/project/login.php. Here are the login.php codes:
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
error_reporting(E_ERROR);
try{
$conn = new mysqli("127.0.0.1", "root", "root", "bencoolen");
$userid = $_GET["userid"];
$password = $_GET['password'];
$query = "SELECT count(*) as found from profiles where userid ='" .
$userid . "' and password = '" . $password . "'";
$result = $conn->query($query);
$count = $result->fetch_array(MYSQLI_NUM);
$json_out = "[" . json_encode(array("result"=>$count[0])) . "]";
echo $json_out;
$conn->close();
}
catch(Exception $e) {
$json_out = "[".json_encode(array("result"=>0))."]";
echo $json_out;
}
?>
I have made sure that the database 'bencoolen' was created with a table called 'profiles' containing both 'userid' and 'password' fields.
I have also downloaded 'PHP Development Tool' on Eclipse and all my php codes syntax are highlighted. Eclipse could also run the javascript and html codes before the I have added login.php. Eclipse directed me to Line 12, with the Fatal error, which was:
$count = $result->fetch_array(MYSQLI_NUM);
Heres my unsupported theory: I think they do not recognise my userid and password fields because the PHP file is not connected to the database due to its file location