gazalec Posted March 8, 2007 Share Posted March 8, 2007 Hi what i want to do i use one PHP page to display a welcome page (eventually the whole website will be like this) and at the index.htm page there is the option to enter or login and if the customer just enters then it says Welcome Guest with login option, whereas if they login it welcomes them with their name and instead of login is has Previous Orders, View Basket and Logout. I know how to do this to an extent, i know it's alot of if statements anyway, i'm having a problem with sessions, when i experimented i got the Guest part to come up but not the name, and then i got the name to come up but if i tried to enter as a guest it would bring up an index error because there was no $cust variable My Code session_start(); $cust=$_POST['cust_no']; /*from previous login page, text field name is cust_no if($cust == ''){ echo "Guest <br>"; } else { [access the database and retrieve name (variable $name)] echo $name ; } Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/ Share on other sites More sharing options...
paul2463 Posted March 8, 2007 Share Posted March 8, 2007 I am assuming that if you enter as a user the $cust variable will be set and if you enter as a guest it wont - just thought I would point out the assumptions used in the following code if (isset($cust)) { //pull information from the database and get the name } else { echo "Guest <br>"; } if you are using $_POST variables then you do not need a SESSION starting Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202654 Share on other sites More sharing options...
magnetica Posted March 8, 2007 Share Posted March 8, 2007 Try: if(empty($cust)){ echo "Guest <br />"; } elseif (!empty($cust)) { [access the database and retrieve name (variable $name)] echo $name ; } Same as what you had but cleaner Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202655 Share on other sites More sharing options...
magnetica Posted March 8, 2007 Share Posted March 8, 2007 if (isset($cust)) { //pull information from the database and get the name } else { echo "Guest <br>"; } By the way this If Statement will always return true because the variable $cust is set but might or might not be empty. Hence the use of the if (empty($cust)) Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202657 Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 if (!empty($_POST['cust_no'])){ //pull information from the database and get the name } else{ echo "Guest <br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202659 Share on other sites More sharing options...
gazalec Posted March 8, 2007 Author Share Posted March 8, 2007 No but thats wot i mean i need it to be part of a session because it is going to be used on all pages i only had post because its the only way i knew how to get information from the previous form Thanks Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202660 Share on other sites More sharing options...
magnetica Posted March 8, 2007 Share Posted March 8, 2007 Well on the second page, doo something like this: $cust = $_POST['form_variable']; $_SESSION['session_cust'] = $cust; Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202662 Share on other sites More sharing options...
gazalec Posted March 8, 2007 Author Share Posted March 8, 2007 this will probably sound really dumb but wot is the session variable then, $session_cust or just $cust Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202666 Share on other sites More sharing options...
paul2463 Posted March 8, 2007 Share Posted March 8, 2007 you will call the session variable on other pages $_SESSION['session_cust']; Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202668 Share on other sites More sharing options...
magnetica Posted March 8, 2007 Share Posted March 8, 2007 Right if you want to learn about session and how to store into the session and retrieve from it then check this video out: http://www.phpvideotutorials.com/lesson12/ Or simply goto Google and search for "sessions and php" Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202670 Share on other sites More sharing options...
gazalec Posted March 8, 2007 Author Share Posted March 8, 2007 ok thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/41790-session-help/#findComment-202674 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.