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 Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
revraz Posted November 9, 2010 Share Posted November 9, 2010 So what is the actual problem? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.