Paul-D Posted 11 hours ago Share Posted 11 hours ago Hi, I am still having problems with a web page. I have talked about this before and nobody could help. I have done more research into this. The webpage Statement.php displays a bank statement within certain dates and how this information is to be displayed using a session variable $_SESSION['CounterValue']. This page gets auto refreshed. I very occasionally get a null error on the function. Uncaught Error: Call to a member function fetch() on null Statement.php Lines 14-17: $View = 'Show'; if (isset($_SESSION['CounterValue'])) $View = $_SESSION['CounterValue']; Statement.php Line 131: $stmt = GetAllData($Date,$View); Session variables do time out but the code should default to = 'Show'. I have been capturing the data before calling the function GetAllData() Data table entries 35, '2025-08-01', '1754065485', '86.1.133.80', '2025-07-31-Show', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36', 'N'), (36, '2025-08-01', '1754079812', '86.1.133.80', '2025-07-31-', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36', 'N'), (37, '2025-08-01', '1754079819', '86.1.133.80', '2025-07-31-Show', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36', 'N'), Entry 36 has '2025-07-31 -' the variable is missing in the call to the function GetAllData. Here is the function in a seperate functions file. Function in separate file function GetAllData($StartDate, $View) { StoreData($StartDate ."-" . $View); // *** Store data to trap this error *** $pdo = connectDB(); if($View == 'Show' or $View == 'Show+' ) { $sqlAllData = "SELECT * FROM Bank_Data WHERE EntryDate > ? AND EntryDate <= DATE_ADD(?, INTERVAL 6 WEEK) ORDER BY EntryDate ASC, Output"; $stmt = $pdo->prepare($sqlAllData); $stmt->execute( [ $StartDate, $StartDate] ); return $stmt; } if($View == 'Total' or $View == 'Database' ) { $sqlAllData = "SELECT * FROM Bank_Data ORDER BY EntryDate ASC, Output"; $stmt = $pdo->prepare($sqlAllData); $stmt->execute(); return $stmt; } } Can anyone find out what is happening to my ($_SESSION['CounterValue'] and why is it not defaulting to $View = 'Show' This is driving me mad now as it has been going on ever since I upgrades this to PDO last year. Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/ Share on other sites More sharing options...
mac_gyver Posted 10 hours ago Share Posted 10 hours ago $_SESSION['CounterValue'] may be set, but doesn't contain what you think. either use var_dump() on $view to display what it is or use var_export(), with the 2nd parameter set to true, when you supply it to the StoreData() call to cause it's value (empty string '', null, false, or true) to be used. best guess is you have some code assigning a value to it, using one =, instead of testing the value in it using two == or three ===. Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1657999 Share on other sites More sharing options...
Paul-D Posted 3 hours ago Author Share Posted 3 hours ago (edited) On log in depending on the user the session can only be set to 1 of the 4 valuse. Show, Show+, Database or Total. So if it is set it will have one of them. By default it is set to Show. Also it is stable for quite some time before it errors on an auto refresh. Either way it will contain a valid string. Edited 3 hours ago by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1658030 Share on other sites More sharing options...
mac_gyver Posted 2 hours ago Share Posted 2 hours ago obviously it is not. you must determine what the non-printing value actually is and find where in your code it's being set to that value. you either have an assignment, instead of a comparison, like i already wrote, or you have some code that's running, such as after a redirect, where you didn't stop php code execution, and it's assigning a value that when echoed is an empty value. Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1658031 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.