01hanstu Posted November 9, 2010 Share Posted November 9, 2010 Hi, I am trying to get the value of a session veriable and if the variable contains a certain word it will show an error message, else just continue as normal. if (isset($_POST['selectroom'])) {$_SESSION['room'] = $_POST['selectroom'];} if (!isset($_SESSION['room'])) $room = "RoomNameA"; else $room = $_SESSION['room']; Please Advise, - Stuart Link to comment https://forums.phpfreaks.com/topic/218191-php-session/ Share on other sites More sharing options...
trq Posted November 9, 2010 Share Posted November 9, 2010 I don't see any call to session_start. Link to comment https://forums.phpfreaks.com/topic/218191-php-session/#findComment-1132181 Share on other sites More sharing options...
01hanstu Posted November 9, 2010 Author Share Posted November 9, 2010 That is at the top of the page! Link to comment https://forums.phpfreaks.com/topic/218191-php-session/#findComment-1132182 Share on other sites More sharing options...
revraz Posted November 9, 2010 Share Posted November 9, 2010 So what is the actual problem? Link to comment https://forums.phpfreaks.com/topic/218191-php-session/#findComment-1132193 Share on other sites More sharing options...
rwwd Posted November 9, 2010 Share Posted November 9, 2010 missing the curlies from the else there, try to keep to one standard, don't mix and match - bad practise. use isset() then !empty() this proves as it's there and has state... Ideally, you need to post more of the code so we can see what else is going on in there. Rw Link to comment https://forums.phpfreaks.com/topic/218191-php-session/#findComment-1132211 Share on other sites More sharing options...
Adam Posted November 9, 2010 Share Posted November 9, 2010 Personally I'd structure it like this: if (!empty($_POST['selectroom'])) { $room = htmlentities($_POST['selectroom']); $_SESSION['room'] = $room; } elseif (isset($_SESSION['selectroom'])) { $room = $_SESSION['selectroom']; } else { $room = "RoomNameA"; } Perhaps drop the htmlentities call if you escape the value somewhere else. Link to comment https://forums.phpfreaks.com/topic/218191-php-session/#findComment-1132218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.