vagzaf Posted August 10, 2021 Share Posted August 10, 2021 Hello, I have developed a page selecting and displaying data from a DataBase(mysql), as following $result = mysqli_query($conn, $sql); $fetch = mysqli_fetch_row($result); $row_code = $fetch[0]; session_start(); $_SESSION['pel_seqno'] = $row_code; The above page has tabs. In the second tab i access the $_SESSION['pel_seqno'] as following <?php $seqno_pel=''; $seqno_pel = $_SESSION['pel_seqno']; I use $seqno_pel variable to retrieve some other data from another table in the DataBase. So far so good, Inside the tab i have a button redirecting in another page and i want to use the value of $_SESSION['pel_seqno']; and i can not. The code which i am trying to access again the $_SESSION['pel_seqno']; is the following <?php $seqno_pel = $_SESSION['pel_seqno']; When the button is pressed i get the following error message Warning: Undefined variable $_SESSION in D:\PROGRAMS\XAMPP\htdocs\CARDIO\Pel_Rv.php on line 5 Warning: Trying to access array offset on value of type null in D:\PROGRAMS\XAMPP\htdocs\CARDIO\Pel_Rv.php on line 5 Is it possible someone to help me with this. Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/313526-session-problem/ Share on other sites More sharing options...
ginerjm Posted August 10, 2021 Share Posted August 10, 2021 Obviously you didn't start the session in this script execution. I always place the session start line at the top of my scripts. It certainly doesn't hurt. Don't do it somewhere else that you think it will happen when it needs to. At the top where you can be sure it happens. Quote Link to comment https://forums.phpfreaks.com/topic/313526-session-problem/#findComment-1588987 Share on other sites More sharing options...
vagzaf Posted August 10, 2021 Author Share Posted August 10, 2021 Thanks you for your answer When i place the session_start() at the begining of the script, then the following error occurred ( Notice: session_start(): Ignoring session_start() because a session is already active in Pel_Rv.php on line 5 ), but the code runs correctly. My code is <? php $seqno_pel=''; session_start(); error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment https://forums.phpfreaks.com/topic/313526-session-problem/#findComment-1588990 Share on other sites More sharing options...
vagzaf Posted August 10, 2021 Author Share Posted August 10, 2021 i changed the error_reporting(E_ALL); to error_reporting(E_ERROR); and the error message disappeared. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/313526-session-problem/#findComment-1588992 Share on other sites More sharing options...
Barand Posted August 10, 2021 Share Posted August 10, 2021 Ah yes. The "bury your head in the sand" method. If you can't see them, the errors don't exist. Quote Link to comment https://forums.phpfreaks.com/topic/313526-session-problem/#findComment-1588994 Share on other sites More sharing options...
ginerjm Posted August 10, 2021 Share Posted August 10, 2021 As Barand is saying you should change back to all errors. Ignoring warnings is not a good idea. Apparently you are already issuing the session start in an earlier part of your executing script. One should place the session start in that place always and not in any 'included' modules later on. That is what it looks like you are doing. The script that your url is calling is the starting point - session start s/b there as close to the start as allowed. Quote Link to comment https://forums.phpfreaks.com/topic/313526-session-problem/#findComment-1588995 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.