princeofpersia Posted November 24, 2010 Share Posted November 24, 2010 Hi guys I need to know how i can create a session for userid from my database, I have done the session for username but not being able to do it for user name, here is my code. my database table is called users and I can login successfully, but i tried few code and it wont show the user id, the column for user id is 'id' <?php include 'global.php'; $session_username = $_SESSION['username']; if ($_POST['login']) { //get form data $username = addslashes(strip_tags($_POST['username'])); $password = addslashes(strip_tags($_POST['password'])); if (!$username||!$password) echo "Enter a username and password"; else { //log in $login = mysql_query("SELECT * FROM users WHERE username='$username'"); if (mysql_num_rows($login)==0) echo "No such user"; else { while ($login_row = mysql_fetch_assoc($login)) { //get database password $password_db = $login_row['password']; //encrypt form password $password = md5($password); //check password if ($password!=$password_db) echo "Incorrect password"; else { //check if active $active = $login_row['active']; $email = $login_row['email']; if ($active==0) echo "You haven't activated your account, please check your email ($email)"; else { $_SESSION['username']=$username; //assign session header('Location:my.php'); } } } } } } else { if (isset($session_username)) { echo "You are logged in, $session_username., <a href='logout.php'>Log out</a>"; } else { echo " <form action='index.php' method='POST'> Username: <input type='text' name='username'><p /> Password: <input type='password' name='password'><p /> <input type='submit' name='login' value='Log in'> </form> "; } } ?> thanks Quote Link to comment Share on other sites More sharing options...
princeofpersia Posted November 24, 2010 Author Share Posted November 24, 2010 anyone? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 24, 2010 Share Posted November 24, 2010 Users should not "bump" topics that are still on the first page of the forums. If you bump, you must provide additional information. If you resort to bumping, chances are your question needs to be re-thought and re-described (see Eric Raymond's "How To Ask Questions The Smart Way"). Quote Link to comment Share on other sites More sharing options...
herghost Posted November 24, 2010 Share Posted November 24, 2010 why dont you create a query that finds id based on username? Quote Link to comment Share on other sites More sharing options...
princeofpersia Posted November 24, 2010 Author Share Posted November 24, 2010 thats what i need to do but i dont know how Quote Link to comment Share on other sites More sharing options...
princeofpersia Posted November 24, 2010 Author Share Posted November 24, 2010 and then also how i make it to be a session for user id? 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.