ash992 Posted July 5, 2012 Share Posted July 5, 2012 Hey guys, Before I say my problem I'de just like to say that I'm new to PHP So there's a good chance it's a simple mistake. On my index there's a form with a text input that takes someones organisations name, there's also a select in the same form, this form redirects to a PHP file that decides what page you will be redirected to, depending on what you chose in the select box, The organisation name is set on the main page through the text input, and the session is set on the form's action, but when it re-directs to the new header the session is not working. $Companyname = $_POST['Companyname']; $_SESSION['CNAME'] = $_POST['Companyname']; That's the pieces of code that should set it, after that it redirects to the header sucsessfully, but when i try to echo the session variable, or even add it to a normal variable to echo it, It doesn't work. Additional information includes, I have started the session on the Index, and again on the form's action file, and again on the header of that file, so the session is started on all of them. Anyone got any Ideas? I really don't know what's wrong with it really.. Thank's in advanced everyone. Link to comment https://forums.phpfreaks.com/topic/265272-session-not-working/ Share on other sites More sharing options...
scootstah Posted July 5, 2012 Share Posted July 5, 2012 Are you sure $_POST['Companyname'] has a value? Link to comment https://forums.phpfreaks.com/topic/265272-session-not-working/#findComment-1359424 Share on other sites More sharing options...
ash992 Posted July 5, 2012 Author Share Posted July 5, 2012 Yep, If i remove the header so it stays on that page, and try to echo $_SESSION['CNAME'] Then it works fine, but if i try to echo it on the file that it re-directs to then there is no output. :s Thank-you for the help and the fast reply, Link to comment https://forums.phpfreaks.com/topic/265272-session-not-working/#findComment-1359425 Share on other sites More sharing options...
scootstah Posted July 5, 2012 Share Posted July 5, 2012 Just to clarify, all of the files in question start like this, right? <?php session_start(); Link to comment https://forums.phpfreaks.com/topic/265272-session-not-working/#findComment-1359428 Share on other sites More sharing options...
ash992 Posted July 5, 2012 Author Share Posted July 5, 2012 They do indeed, and the code on the file it redirects to is here <?php session_start(); $_SESSION['CNAME'] = $cpnamerrr; echo $cpnamerrr; ?> And I'm not getting any output? it also doesn't work if I just try to echo the $_SESSION['CNAME'] straight away, The reason I'm turning it into a normal variable instead of a Session by the way is because I use it later on in a form for it's value, Thanks again. Link to comment https://forums.phpfreaks.com/topic/265272-session-not-working/#findComment-1359432 Share on other sites More sharing options...
scootstah Posted July 5, 2012 Share Posted July 5, 2012 You've got that a bit backwards. $cpnamerrr = $_SESSION['CNAME']; Link to comment https://forums.phpfreaks.com/topic/265272-session-not-working/#findComment-1359433 Share on other sites More sharing options...
ash992 Posted July 5, 2012 Author Share Posted July 5, 2012 Ahaha! It's working fine now! Thank-you very much Link to comment https://forums.phpfreaks.com/topic/265272-session-not-working/#findComment-1359434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.