Author Topic: Undefined Array After Updating to PHP 8.1  (Read 883 times)

0 Members and 1 Guest are viewing this topic.

Offline scottct1

  • Senior Member
  • **
  • Posts: 74
    • Newington, CT Weather
Undefined Array After Updating to PHP 8.1
« on: March 21, 2023, 10:12:50 AM »
Moved the site from PHP 7.4 up to 8.1 today.   Most of the page came up blank. (I am using the Burnsville Alternative script)

So I went over to Kens site and downloaded the latest version. I updated the AltAjaxDashboardConfig6.php with my settings and uploaded and overwrote all the files and everything is displaying... well almost.

Below the header I see the following...

Quote
Warning: Undefined array key 0 in /home/weather/public_html/raintodate.php on line 124

Warning: Trying to access array offset on value of type null in /home/weather/public_html/raintodate.php on line 124

Warning: Undefined array key 1 in /home/weather/public_html/raintodate.php on line 124

Warning: Trying to access array offset on value of type null in /home/weather/public_html/raintodate.php on line 124

Warning: Undefined array key 2 in /home/weather/public_html/raintodate.php on line 124

Warning: Trying to access array offset on value of type null in /home/weather/public_html/raintodate.php on line 124

Warning: Undefined array key 3 in /home/weather/public_html/raintodate.php on line 124

Warning: Trying to access array offset on value of type null in /home/weather/public_html/raintodate.php on line 124

Warning: Undefined variable $month_rain in /home/weather/public_html/raintodate.php on line 127

Not sure what this means or how to get rid of it.

The site is https://NewingtonWeather.COM
It is running off of WeatherDisplay with a Davis Vantage 2 Plus with Solar and UV, as well as lightning from Tempest.

If Ken or anyone can help out I would be very greatful. :D   Thank you!
Scott - NewingtonWeather.COM - Newington, Connecticut's Weather Source!
Davis Vantage Pro 2 Plus - WeatherFlow Tempest for Lightning - Weather-Display Software

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9560
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Undefined Array After Updating to PHP 8.1
« Reply #1 on: March 21, 2023, 10:32:34 AM »
Did you also replace the other php scripts in the update .zip?
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline scottct1

  • Senior Member
  • **
  • Posts: 74
    • Newington, CT Weather
Re: Undefined Array After Updating to PHP 8.1
« Reply #2 on: March 21, 2023, 10:37:52 AM »
Yes uploaded them all.  Including the directories.

Just deleted them and reuploaded them now. Still getting the same thing.  I assume the update zip file is this one "https://saratoga-weather.org/legacy-scripts/AltAjaxDashboard695g.zip"

Thanks Ken for your quick reply.
« Last Edit: March 21, 2023, 11:04:51 AM by scottct1 »
Scott - NewingtonWeather.COM - Newington, Connecticut's Weather Source!
Davis Vantage Pro 2 Plus - WeatherFlow Tempest for Lightning - Weather-Display Software

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9560
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Undefined Array After Updating to PHP 8.1
« Reply #3 on: March 21, 2023, 11:36:58 AM »
Try replacing in raintodate.php
Code: [Select]
function get_mtd_rain ($start_year,$day,$month,$year,$loc)
{
$years = $year - $start_year;
$months = 0;   
for ($i = 0 ; $i < $years ; $i++)
    {   
$filename = "dailynoaareport" . ( $month) . ($start_year + $i) . ".htm";

if (file_exists($loc . $filename) )   
    {
    $data[0] = getnoaafile($loc . $filename);
    $months = $months + 1;
    // Now get data from the dailynoaareport for this month from the 1st to today's date'.

    for ($d = 0 ; $d < $day ; $d++)
        {
        $rain = $data[0][$d][8];
        if ($rain != "")
           {
           $month_rain = $month_rain + $rain;
                   
           }   
        }
    }
    }
with
Code: [Select]
function get_mtd_rain ($start_year,$day,$month,$year,$loc)
{
$years = $year - $start_year;
$months = 0;
$month_rain = 0;   
for ($i = 0 ; $i < $years ; $i++)
    {   
$filename = "dailynoaareport" . ( $month) . ($start_year + $i) . ".htm";

if (file_exists($loc . $filename) )   
    {
    $data[0] = getnoaafile($loc . $filename);
    $months = $months + 1;
    // Now get data from the dailynoaareport for this month from the 1st to today's date'.

    for ($d = 0 ; $d < $day ; $d++)
        {
        $rain = isset($data[0][$d][8])?$data[0][$d][8]:'';
        if ($rain != "")
           {
           $month_rain = $month_rain + $rain;
                   
           }   
        }
    }
    }
« Last Edit: March 21, 2023, 11:56:13 AM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline scottct1

  • Senior Member
  • **
  • Posts: 74
    • Newington, CT Weather
Re: Undefined Array After Updating to PHP 8.1
« Reply #4 on: March 21, 2023, 11:53:43 AM »
Thanks Ken, tried it and am getting an error of Parse error: Unclosed '{' on line 124 does not match ')' in /home/weather/public_html/raintodate.php on line 125

Here is the code after I changed it... (Including the entire section, incase I messed something up)

Code: [Select]
########## Functions ##########################################################

function get_mtd_rain ($start_year,$day,$month,$year,$loc)
{
$years = $year - $start_year;
$months = 0;
$month_rain = 0;
for ($i = 0 ; $i < $years ; $i++)
    {
$filename = "dailynoaareport" . ( $month) . ($start_year + $i) . ".htm";

if (file_exists($loc . $filename) )
    {
    $data[0] = getnoaafile($loc . $filename);
    $months = $months + 1;
    // Now get data from the dailynoaareport for this month from the 1st to today's date'.

    for ($d = 0 ; $d < $day ; $d++)
        {
        $rain = isset($data[0][$d][8])?$data[0][$d][8]):'';
        if ($rain != "")
           {
           $month_rain = $month_rain + $rain;

           }
        }
    }
    }

if ($months == 0) {
    $mtd_rain = 0;
} else {
        $mtd_rain = $month_rain / $months;
       }
return $mtd_rain;
}


############################################################################
# End of Functions
############################################################################
Scott - NewingtonWeather.COM - Newington, Connecticut's Weather Source!
Davis Vantage Pro 2 Plus - WeatherFlow Tempest for Lightning - Weather-Display Software

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9560
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Undefined Array After Updating to PHP 8.1
« Reply #5 on: March 21, 2023, 11:57:19 AM »
My bad...

Change
Code: [Select]
$rain = isset($data[0][$d][8])?$data[0][$d][8]):''; to
Code: [Select]
$rain = isset($data[0][$d][8])?$data[0][$d][8]:'';
That happens when I copy/paste and select a bit too much.   #-o
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline scottct1

  • Senior Member
  • **
  • Posts: 74
    • Newington, CT Weather
Re: Undefined Array After Updating to PHP 8.1
« Reply #6 on: March 21, 2023, 12:00:29 PM »
Yes that fixed it!

Thanks Ken!
Scott - NewingtonWeather.COM - Newington, Connecticut's Weather Source!
Davis Vantage Pro 2 Plus - WeatherFlow Tempest for Lightning - Weather-Display Software