derekbelcher Posted April 22, 2009 Share Posted April 22, 2009 I am trying to switch from the antique code to what is recognized today. Previous code that worked fine: if(!session_is_registered(myusername)){ header("location: and so on. What I want to use is $_SESSION. I tried this: if($_SESSION[(myusername)]{ header("location: and so on. Can someone help me find the error of my way :-) Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/155219-solved-is-this-statement-rightif-not-how-do-i-write-this/ Share on other sites More sharing options...
premiso Posted April 22, 2009 Share Posted April 22, 2009 if (isset($_SESSION['myusername'])) { Quote Link to comment https://forums.phpfreaks.com/topic/155219-solved-is-this-statement-rightif-not-how-do-i-write-this/#findComment-816570 Share on other sites More sharing options...
derekbelcher Posted April 22, 2009 Author Share Posted April 22, 2009 thank you. Now next question: I had this code which output the first and last name of the person with the user id that was used at login, and now it won't work. It worked with session_is_registered, but not with the new $_SESSION. <?PHP $firstname = $_POST['firstname'] ; $lastname = $_POST['lastname'] ; $user = $_POST['username'] ; $sql = "SELECT * FROM `officers` WHERE username = '{$_SESSION['myusername']}'" ; $result = mysql_query($sql) ; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $dbfname = $row['firstname'] ; $dblname = $row['lastname'] ; $dbuser = $row['username'] ; } echo "$dbfname $dblname" ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/155219-solved-is-this-statement-rightif-not-how-do-i-write-this/#findComment-816579 Share on other sites More sharing options...
radi8 Posted April 22, 2009 Share Posted April 22, 2009 Well, from what I saw, you never defined the $_SESSION['username'] variable, but you are defining the $user from the $_POST variable, so use that: <?PHP $firstname = $_POST['firstname'] ; $lastname = $_POST['lastname'] ; $user = $_POST['username'] ; // use the $user here instead $sql = "SELECT * FROM `officers` WHERE username = '".$user."'" ; $result = mysql_query($sql) ; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $dbfname = $row['firstname'] ; $dblname = $row['lastname'] ; $dbuser = $row['username'] ; } echo "$dbfname $dblname" ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/155219-solved-is-this-statement-rightif-not-how-do-i-write-this/#findComment-816588 Share on other sites More sharing options...
derekbelcher Posted April 22, 2009 Author Share Posted April 22, 2009 Still didn't work. It's just blank where the name should be appearing. How do I define the $_SESSION variable you mentioned? Sorry, very new to some of this. Quote Link to comment https://forums.phpfreaks.com/topic/155219-solved-is-this-statement-rightif-not-how-do-i-write-this/#findComment-816596 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.