SN1P3R_85 Posted December 5, 2008 Share Posted December 5, 2008 Hi, I have a script where people can register on my site, and it works, but there is a problem with it. If the register goes through, it is supposed to log them on as well. On my site logging on consists of three parts, username, userlevel, and validate. I set three php sessions with these values. It sets the username and validate fine, but it won't set userlevel. Userlevel is in the same table as username, so I don't know why it won't work. However, when i use the login script, it sets it. $query = "INSERT INTO `users` (Username, Password, Userlevel, Email) VALUES ('$username', '$password', '$usr_level', '$email')"; $result = mysql_query($query); if ($result) { $_SESSION['username'] = $row['Username']; $_SESSION['userlevel'] = $row['Userlevel']; $_SESSION['uservalid'] = true; echo "registration successful, you are a " . $row['Userlevel'] . "."; } Quote Link to comment Share on other sites More sharing options...
ram4nd Posted December 5, 2008 Share Posted December 5, 2008 You have to start the session before using that. Quote Link to comment Share on other sites More sharing options...
SN1P3R_85 Posted December 5, 2008 Author Share Posted December 5, 2008 I did, its up above, i didn't show the entire code Quote Link to comment Share on other sites More sharing options...
SN1P3R_85 Posted December 5, 2008 Author Share Posted December 5, 2008 the problem isn't that i can't get the session to set, its that the row['Userlevel'] doesn't seem to exist. I tested it by putting this in : echo $row['Userlevel']; and it still didn't work. Quote Link to comment Share on other sites More sharing options...
PravinS Posted December 5, 2008 Share Posted December 5, 2008 You didn't fetched the records from the $result. use $row = mysql_fetch_row($result); in if condition. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted December 5, 2008 Share Posted December 5, 2008 <?php $query = "INSERT INTO `users` (Username, Password, Userlevel, Email) VALUES ('$username', '$password', '$usr_level', '$email')"; $result = mysql_query($query); if ($result) { $row = mysql_fetch_assoc($result); $_SESSION['username'] = $row['Username']; $_SESSION['userlevel'] = $row['Userlevel']; $_SESSION['uservalid'] = true; echo "registration successful, you are a " . $row['Userlevel'] . "."; } ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 5, 2008 Share Posted December 5, 2008 Please read a basic mysql book or a mysql tutorial before attempting to use mysql. Fetching a row of data from the result set before using that data is basic understanding of how to use a database. And please learn php, develop php code, and debug php code on a development system with error_reporting set to E_ALL and display_errors set to ON to get php to help you. The missing $row[..] variables would have triggered error messages to help you discover that there is no code setting them. 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.