I did research other threads that were similar questions, but my situation seems to be unique. I am using a PHP function that I created to find a single row in a table based on two parameters in the "WHERE" clause. When the function is used, the resulting HTML is exactly what I expect, and the data is filled in from this function, but I still get a PHP error:
"PHP Warning: Trying to access array offset on value of type null in /var/www/html/functions/resolve_functions.php on line 66"
Here is my function:
function resolve_feature_device($feature, $device) {
$conn = db_connect(); // Connect to the configurator database
// Build the query to retrieve the partnum based on the feature provided
$result = $conn->query("SELECT txt_partnum
FROM tbl_device_feature
WHERE txt_feature='$feature'
AND txt_partnum='$device';");
// If the result is false, return false to the calling procedure, else return the resulting value
if (!$result) {
return false;
} else {
$row = $result->fetch_assoc();
$device = $row["txt_partnum"]; // This is line 66
if (isset($device)) {
return $device;
} else {
return false;
}
}
}
The database table is a list of part numbers and features, so there are multiple rows with the same part number, and multiple rows with the same feature, but there should only be one unique row that has both a specific part number combined with a specific feature.
I don't understand why the function provides me with the expected output, yet still gives a PHP error message. The output obviously isn't "null". Any guidance would be greatly appreciated.
- PHP 8.1.1
- Apache 2.4.37
- MariaDB 10.3.28
- Rocky Linux 8.5