Paul-D Posted August 5 Share Posted August 5 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 August 5 Share Posted August 5 $_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 August 5 Author Share Posted August 5 (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 August 5 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 August 5 Share Posted August 5 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...
mac_gyver Posted August 6 Share Posted August 6 this is apparently the previous related thread - https://forums.phpfreaks.com/topic/321226-pdo-error-on-function-since-a-migration-to-pso at that time, the "Statement.php Lines 14-17" were in a file being included before the session_start() and would never have found the session variable set. i'm going to guess that the "fetch() on null error" was occurring on every page request? you have since moved these lines to statement.php. after reviewing the code you posted previously, if this problem is only occurring occasionally, it is likely due to some auto logout logic, a page auto reload occurring exactly at the point of being logged out, and a timing/race condition in the logic, due to all these session variables. at the risk or repeating myself. the only piece of user related data you should store in a session variable upon successful login is the user id (autoincrement primary index.) you should query on each page request to get any other user data, so that any changes made to this other user data take effect on the very next page request. if you cannot determine the cause of this problem, you will need to post all the current code for statemnt.php, everything being included (you should use require for things your code must have) by statement.php, everything those files are including, and index.php (and everything it includes and everything those files include) since it is involved in the redirects and could be redirecting back to statement.php, less any database credentials or sensitive site information (which should be in a configuration .php file), for anyone here to be able to help. 1 Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1658037 Share on other sites More sharing options...
Paul-D Posted yesterday at 08:13 AM Author Share Posted yesterday at 08:13 AM (edited) Here is the whole statment.php. As you can see on line 14. I have set the value to Show. It can only be changed if the if statment below changes it [Lines 15 and 16]. So this value can not be NULL EVER. I added lines 125 to 128 as a way of capturing null but this never gets trapped EVER? Line 133 failes with the returning null error. I am supplying the functions file SecureFunctionsBankPDO as well. The function GetAllData is on line 28 Statment.php <?php // Banking Version 2.0.0 01-12-2023 Desmond O'Toole. // Banking Version 2.0.0 01-12-2023 Desmond O'Toole. error_reporting(E_ALL); ini_set('display_errors', '1'); require ("secure/SecureFunctionsBankPDO.php"); require ("../secure/SecurePDO.php"); //session_unset(); $page = "Bank Login"; session_start(); Session_Init(); $View = 'Show'; if (isset($_SESSION['CounterValue'])) $View = $_SESSION['CounterValue']; if(!isset($_SESSION["Pk"])) { header('Location: index.php'); exit; } $Pk = $_SESSION["Pk"]; if(KeyCheckX($Pk)== 0) { header('Location: index.php'); exit; } //$EndTime = KeyTestX($Pk, 0); $EndTime = KeyShowX($Pk); $_SESSION["current_page"] = $page; $qBalance = GetBalance(); $Date = $qBalance['EntryDate']; $Value = $qBalance['BalanceValue']; $stamp = strtotime($Date); $StartDate = date('D d-M-Y' ,$stamp); $stamp = $stamp + (WEEKS * 6) + (DAYS * 1); $EndDataDate = date('D d-M-Y' ,$stamp); //$QueryDate = date('d-M-Y' ,$stamp); $curValue = $Value; /* $Cash = number_format(MonthlyTakings(CASH) , 2, ".", ","); $Shops = number_format(MonthlyTakings(SHOPS) , 2, ".", ","); $Online = number_format(MonthlyTakings(ONLINE) , 2, ".", ","); $Other = number_format(MonthlyTakings(OTHER) , 2, ".", ","); $Ebay = number_format(MonthlyTakings(EBAY) , 2, ".", ","); //$Totals = $Cash + $Shops + $Online + $Other; $Totals = number_format($Cash + $Shops + $Online + $Other + $Ebay , 2, ".", ","); */ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Bank Home 2</title> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META http-equiv="imagetoolbar" CONTENT="no"> <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Expires" content="0"> <meta http-equiv="refresh" content="600"> <link rel="stylesheet" href="stylesheets/Library.css" type="text/css"> <link rel="stylesheet" href="stylesheets/LibraryMenu.css" type="text/css"> </head> <body> <div id="PageTitle"> <img src="images/LibraryBanner.jpg" alt=""> </div> <?php include('SideMenu.php'); ?> <div id="PageContent"> <form action="menu.php" method="post"> <span style="color:blue;"><b>Est: 18-July-2015</b></span> <h4><?= "Displayed data up to " . $EndDataDate?><?="<br>Log on ends on " . $EndTime?> <a href="DeleteOldData.php"><span style="color:blue">Clear old data</span></a> <br> </h4> <div style="width:820px;padding:0px;float:left;"> <div style="width:120px;height:10px;padding:10px;float:left;"><b> Date</b> </div> <div style="width:70px;height:10px;padding:10px;float:left;"><b>Money In</b> </div> <div style="width:70px;height:10px;padding:10px;float:left;"><b>Money Out</b> </div> <div style="width:70px;height:10px;padding:10px;float:left;"><b>Balance</b> </div> <div style="width:100px;height:10px;padding:10px;float:left;"><b>Reason</b> </div> <div style="width:230px;height:10px;padding:10px;float:left;"><b>Comment</b> </div> <div style="width:120px;height:4px;padding:8px;text-align:right;float:left;clear:both;"><a style="color:#ae22e2;" href="DataInput.php">* <?=$StartDate?></a> </div> <div style="width:70px;height:4px;padding:10px;text-align:right;float:left;"> </div> <div style="width:70px;height:4px;padding:10px;text-align:right;float:left;"> </div> <div style="width:70px;height:4px;padding:10px;text-align:right;float:left;">£<?=number_format( $Value,2,'.',',')?> </div> <div style="width:100px;height:4px;padding:10px;float:left;"> </div> <div style="width:230px;height:4px;padding:10px;float:left;">Brought forward </div> <?php if($Date === null) { echo "$Date = NULL..."; exit; } if($View === null) { echo "$View = NULL..."; exit; } $stmt = GetAllData($Date,$View); while($row = $stmt->fetch()) { $stamp = strtotime($row['EntryDate']); $ViewDate = date('D d-M-Y' ,$stamp); $CurDate = date('D d-M-Y' ,time()); $input = '£' . $row['Input']; if($row['Input'] == '0.00') $input = ""; $out = '£' . $row['Output']; if($row['Output'] == '0.00') $out = ""; $reason = GetReasonName($row['Reason']); $colorSelect = ColourPicker($row['Reason'],$row['EntryDate']); $AddDate = $row['AddDate']; $x = strtotime($AddDate); $MyDate = date("D dS M H:i", $x); $curValue = $Value + $row['Input'] - $row['Output']; //$curValue = RestoreDecimal($curValue); $DisplayCurValue = number_format( $curValue,2,'.',','); $Value = $curValue; $Comment = $row['Comment']; $Comment = str_replace("£","£", $Comment); // $Comment, "£", "£" $Comment = trim($Comment); $Bold = $row['B']; if($Bold == 1) $Comment = "<b>" . $Comment . "</b>"; $ID = TransposeKey($row['Tag']); //$ID = $row['Tag']; $x = ""; if($colorSelect == "#777777") { ?> <div style="width:120px;height:4px;padding:10px;text-align:right;float:left;text-color:green;clear:both;"><dfn title="Test"></dfn><?=$ViewDate?> </div> <?php } else { ?> <div style="width:115px;height:4px;padding:10px;text-align:right;float:left;text-color:green;clear:both;"> <a href="StatementEntry.php?ID=<?=$ID?>" title="<?=$MyDate?>"> <?=$ViewDate?></a></div> <?php } ?> <div style="width:70px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>text-align:right;float:left;"><?=$input?> </div> <div style="width:70px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>text-align:right;float:left;"><?=$out?> </div> <div style="width:70px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>text-align:right;float:left;">£<?=$DisplayCurValue?> </div> <div style="width:100px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>float:left;"><?=$reason?> </div> <div style="width:250px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>float:left;"><?=$Comment?> </div> <?php } ?> <div style="width:70px;height:1px;padding:10px;float:left;clear:both"> </div> </div> <div style="width:670px;height:50px;padding:0px;float:left;"> <input class="MyButton"type="submit" name="direction" value="Main Menu"> <br> </div> </form> </div> </body> </html> SecureFunctionsBankPDO <?php //include_once ("../secure/SecurePDO.php"); error_reporting(E_ALL); ini_set('display_errors', '1'); define ('OTHER', 1); define ('SHOPS', 10); define ('ONLINE', 11); define ('CASH', 12); define ('EBAY', 15); define ('ARGOS', 16); // System time values define ('MINUTES',60); define ('HOURS',(MINUTES * 60)); define ('DAYS',(HOURS * 24) ); define ('WEEKS',(DAYS * 7)); global $View; function GetBalance() { $pdo = connectDB(); $stmt = $pdo->query("SELECT * FROM Bank_config"); $row = $stmt->fetch(); return $row; } function GetAllData($StartDate, $View) { StoreData($StartDate ."-" . $View); // *** Store data to trap this error *** $pdo = connectDB(); if($View == 'Show' or $View == 'Show+' ) //Desmond. or Desmond.. { $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; } } function MonthlyTakings($Cat) // E2011 { $pdo = connectDB(); //$sqlWithdraw = "SELECT Sum(Output) FROM Bank_Data WHERE EntryDate >= '2015-07-07' AND EntryDate <= '2015-08-07' AND (Reason = 1 OR Reason = 10) ORDER BY EntryDate"; $sqlWithdraw = "SELECT Sum(Output) FROM Bank_Data WHERE EntryDate > DATE_ADD( CURDATE() ,INTERVAL -30 DAY) AND EntryDate <= DATE_ADD( CURDATE() ,INTERVAL 0 DAY) AND (Reason = $Cat) ORDER BY EntryDate"; $stmt = $pdo->query($sqlWithdraw); //echo $sqlWithdraw; //exit; $row = $stmt->fetch(); if($row["Output"] != "") $ret = $row[0]; else $ret = "0.00"; return $ret; } function GetReasonName($r) // E2006 { $pdo = connectDB(); $sqlReason = "SELECT Reason FROM Bank_Reason WHERE ReasonID = " . $r; $stmt = $pdo->query($sqlReason); $row = $stmt->fetch(); return $row["Reason"]; } function ColourPicker($ref,$date) // E2007 { $CurDate = time(); $EntryDate = strtotime($date); $Diff = $EntryDate - $CurDate + (DAYS * 3); // Entries allowed to be edited. Less than 0 = Disabled. if($_SESSION['CounterValue'] == "Show") //Desmond. $Diff = $EntryDate - $CurDate + (DAYS * 14); if($_SESSION['CounterValue'] == "Total") //Desmond... $Diff = $EntryDate - $CurDate + (DAYS * 7); if($_SESSION['CounterValue'] == "Database") //Desmond+ $Diff = 1; if ($Diff <0) $Diff = -1; else $Diff = 1; $val = "#000000"; if($ref == 1) $val = "#0000ff"; // Other Blue if($ref == 4) $val = "#ff00ff"; // CT Pink if($ref == 5) $val = "#c51010"; // Energy Burgandy if($ref == 6) $val = "#27b30b"; // TT_M Dark green if($ref == 7) $val = "#06b8b6"; // TT_BB Cyan if($ref == 8) $val = "#00aa00"; // MNOPF Green if($ref == 9) $val = "#aa7700"; // Water Brown if($ref == 10) $val = "#ff0000"; // Shop Red if($ref == 11) $val = "#7777ff"; // Online light Blue if($ref == 15) $val = "#7a061c"; // Ebay Royal green if($ref == 18) $val = "#aa00aa"; // HSBC if($ref == 19) $val = "#aa7700"; // Amazon Orders Brown if($ref == 20) $val = "#301de8"; // State Pension if ($Diff == -1) $val = "#777777"; return $val; } function DeleteOldData() { $pdo = connectDB(); $Date = time(); $Month = date('m' ,$Date); $Year = date('Y' ,$Date); $Month -= 1; if ($Month == 0) { $Month = 12; $Year -= 1; } $Date = $Year . "-" . $Month . "-01"; $sqlOldData = "DELETE from `Bank_Data` Where EntryDate < ? "; // $sqlOldData = "DELETE FROM Bank_Data WHERE EntryDate < CURDATE() - INTERVAL 1 MONTH"; // date('Y-m-d', strtotime('first day of last month')) $stmt = $pdo->prepare($sqlOldData); $return = $stmt->execute([$Date]); } function greeting() // E102 { $pdo = connectDB(); $sql = "SELECT UserF, UserS FROM LIBusersX WHERE User = '" . $_SESSION['Uk'] . "'"; $stmt = $pdo->query($sql); $rs = $stmt->fetch(); echo $rs['UserF'] . " " . $rs['UserS']; } function GetReason() // E2001 { $pdo = connectDB(); $sqlList = "SELECT * FROM Bank_Reason Order by Reason ASC"; $stmt = $pdo->query($sqlList); //$qList = mysql_query($sqlList) or die ("E2001-01A"); return $stmt; } function AddRecord($EntryDate,$input,$out,$Reason,$Comment) // E2002 { $pdo = connectDB(); $AddDateStamp = time(); $AddDate = date("Y-m-d H:i", $AddDateStamp); $Transaction = dechex(strtotime($EntryDate)); $Insertion = dechex(time()); $package = md5($Transaction . $Insertion); $Hilight = 0; $sqlGetCount = "Select * FROM Bank_Data"; $stmt = $pdo->prepare($sqlGetCount); $stmt->execute(); $Count = $stmt->rowCount(); $Count = dechex($Count += 256); $Tag = substr(($Count . $Transaction . $Insertion . $package),0,32); $sqlList = " INSERT INTO Bank_Data SET EntryDate = :Entry, Input = :In, Output = :Out, Reason = :Reason, Comment = :Comment, AddDate = :AddDate, Tag = :Tag, B = :B "; $stmt = $pdo->prepare($sqlList); $stmt->execute([ ':Entry' => $EntryDate, ':In' => $input, ':Out' => $out, ':Reason' => $Reason, ':Comment' => $Comment, ':AddDate' => $AddDate, ':Tag' => $Tag, ':B' => $Hilight ]); return; } function UpdateBalance($BF,$EntryDate) { $pdo = connectDB(); //echo $BF . " - " . $EntryDate; //exit; $sqlBalanceUpdate = "UPDATE Bank_config SET EntryDate = ?, BalanceValue = ?"; $stmt = $pdo->prepare($sqlBalanceUpdate); $stmt->execute([$EntryDate, $BF]); return; } function EntryDetails($Tag) // E2008 { $pdo = connectDB(); $sqlDataEntry = "SELECT * FROM Bank_Data WHERE Tag = ?"; $stmt = $pdo->prepare($sqlDataEntry); $stmt->execute([$Tag]); return $stmt; } function UpdateRecord($EntryDate,$input,$out,$Reason,$Comment,$Bold) // E2009 { $pdo = connectDB(); $Comment = addslashes($Comment); $Tag = $_SESSION['Tag']; $sqlList = "UPDATE Bank_Data SET EntryDate = :Entry, Input = :In, Output = :Out, Reason = :Reason, Comment = :Comment, B = :Bold WHERE Tag = :Tag "; $stmt = $pdo->prepare($sqlList); $stmt->execute([ ':Entry' => $EntryDate, ':In' => $input, ':Out' => $out, ':Reason' => $Reason, ':Comment' => $Comment, ':Bold' => $Bold, ':Tag' => $Tag ]); return; } function DeleteRec($Tag) // E2010 { $pdo = connectDB(); $sqlDeleteRec = "DELETE FROM Bank_Data WHERE Tag = '" . $Tag . "'"; $stmt = $pdo->prepare($sqlDeleteRec); $stmt->execute(); //$stmt->execute([$Tag]); } ?> One point here is that in the function GetAllData, I have added a trap that logs the values passed to this function in a database table Line 36 shows that a variable is missing. I should have the date follows by '-' and the variable $View so I should see '2025-07-31-Show' but on line 36 I get '2025-07-31-'. The variable $View is clearly missing. (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'), These are all the files needed here.. Edited yesterday at 08:23 AM by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1659407 Share on other sites More sharing options...
mac_gyver Posted yesterday at 01:01 PM Share Posted yesterday at 01:01 PM you still haven't done this - On 8/5/2025 at 6:34 AM, mac_gyver said: 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. so, you don't know what the non-printing value actually is. it is likely an empty string '', not a null value. the null in the "Call to a member function fetch() on null" error is because GetAllData() returns nothing (null) when $View doesn't match one of he 4 values. you haven't posted ../secure/SecurePDO.php or SideMenu.php. where is session_init() defined? it's likely setting $_SESSION['CounterValue'] to the offending value. since this code could be redirecting to index.php and back to statement.php, whet is the full code being used on index.php (which i already asked you to post)? do any of these filenames being required/included exist at different paths within your project, so that different parts of your code could be requiring/including a wrong version of a file? i ask this because in the related code you have posted for this problem, there have been different versions of session_init() and variables being used that haven't been assigned a value in any of the posted code. 1 Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1659409 Share on other sites More sharing options...
Paul-D Posted 10 hours ago Author Share Posted 10 hours ago (edited) I can not use var_dump() or var_export(). REASON I would have to waitt hours for this problem to hi-light itself and I would not be able to use the website while I am doing this. I have thought isset() is maybe not the best because it may be set with a zero length string. How about this? if (isset($_SESSION['CounterValue']) && strlen($_SESSION['CounterValue'])> 1 ) //if (isset($_SESSION['CounterValue'])) $View = $_SESSION['CounterValue']; Will have to wait and see. I think it has to do with line 12 - Session_Init(); What it does is set all the SESSION values if not set to null strings and zero's. Edited 10 hours ago by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1659425 Share on other sites More sharing options...
Paul-D Posted 10 hours ago Author Share Posted 10 hours ago (edited) I thought of cleaning this up but I have tried this. . . if (!isset($_SESSION['CounterValue'])) S_SESSION['CounterValue'] = 'Show'; $View = $_SESSION['CounterValue']; But I get this error in the if() statment . - Fatal error: Cannot use temporary expression in write context . . . Edited 9 hours ago by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1659426 Share on other sites More sharing options...
Paul-D Posted 9 hours ago Author Share Posted 9 hours ago (edited) Forget that last one S is not $. Hopefully NOW this will work. fingers crossed. Edited 9 hours ago by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1659428 Share on other sites More sharing options...
mac_gyver Posted 8 hours ago Share Posted 8 hours ago we are not sitting next to you. we don't have all the relevant code. if you won't do the things that have been suggested, we cannot help you. why are not posting the requested code? YOU CAN USE var_export() the way I suggested. this is the current storedata() call - StoreData($StartDate ."-" . $View); // *** Store data to trap this error *** change it to this - StoreData($StartDate ."-" . var_export($View,true)); // *** Store data to trap this error *** throwing random code at the problem won't solve anything. you must find what's causing a problem before you can fix it. you must find what the incorrect value is, then find where and how it is being set to that value. by using all these session variables to make your site 'work', you have created code where values used on one page can get changed by the code on a different page. the solution is to get rid of all the session variables, except for a user id, that identifies who the logged in user is. this 'CounterValue'/view should be a $_GET parameter on the end of the URL, since is determines what will be displayed on a page. Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1659430 Share on other sites More sharing options...
mac_gyver Posted 7 hours ago Share Posted 7 hours ago as a separate post, here is what you actually need to do. you need to start over, update all the code to current standards, organize the code, and have the code for any single operation, such as displaying the statement, on one page. i previously posted this (in fact i'm repeating everything multiple times with you), the code for any page should be laid out in this general order - initialization post method form processing - get/produce data needed to display the page get method business logic - get/produce data needed to display the page html document the only user related session variable should be $_SESSION['user_id'] (autoincrement primary index), to identify who the logged in user is. you should query on each page request to get any other user data, such as the username, role, permissions, ... all user entered input data needs to be trimmed before validating it. all input data to page - $_GET, $_POST, $_FILES, $_COOKEIE, $_SESSION, and some $_SERVER, needs to be validated before using it. if 'required' data is not valid, that's an error, and you would setup and display an error message instead of running code that's dependent on the input data. if input data is optional, and it is not set, you would setup a default value, such as a default view value if there is no view input. your page navigation and the view choice need to be handled using $_GET inputs. here a list of points for the last statement.php and SecureFunctionsBankPDO.php code you posted in this thread - your code should be organized so that you are not repeating yourself. require (and include) is not a function. the () around the path/filename do nothing and should be removed. the list of transaction type/category defined constants should instead be handled via a database table. the global keyword only has meaning inside a function, and even there it should be avoided as it produces code that's hard to debug. every query that has a dynamic value being supplied as an input needs to be a prepared query. due to cross site scripting, even values that come from trusted, logged in users, can be set to anything and cannot be trusted. the discrete logic in MonthlyTakings() will never match $row['Output'], since you are not SELECTing anything named Output. ColourPicker() should NOT directly reference a superglobal variable to get the view. there should be a call-time input parameter for the view. functions should not echo output. they should return the result they produce to the calling code so that the result can be used in any context. don't select all the columns and rows of data from a table just to get a count of number of rows. you should use SELECT COUNT(*) ..., then fetch the count value. don't get a count of the number of rows in a table and use this value as input to another query. this is not concurrent safe. you should not UPDATE a column to keep track of the balance. this can get out of sync with the actual data. you should query the actual data anytime you need to get the balance. the doctype is out of date and needs to be updated. you need to validate the resulting web page at validator.w3.org you need to be consistent. you are using require some places and include elsewhere. you should always use require for things your code must have. as has already been written, you need to use $_GET inputs for navigation, not a post method form. actually, the whole form around the statement content is pointless. you need to use css instead of in-line styling. every dynamic value output in a html context needs to have htmlentities() applied to it right before or as it is being output. Quote Link to comment https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1659432 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.