princeofpersia Posted November 24, 2010 Share Posted November 24, 2010 Hi guys I have created a logged in page which works fine, I need to echo out the user id any ideas would be appreciated my table is called users and idfield 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> "; } } ?> Link to comment https://forums.phpfreaks.com/topic/219746-echo-out-user-id/ Share on other sites More sharing options...
noXstyle Posted November 24, 2010 Share Posted November 24, 2010 How about assiging the id while assigning username? else { $_SESSION['username']=$username; //assign session $_SESSION['userid']=$login_row['id']; header('Location:my.php'); } Then just echo it like you would echo username: echo $_SESSION['userid']; Link to comment https://forums.phpfreaks.com/topic/219746-echo-out-user-id/#findComment-1139193 Share on other sites More sharing options...
princeofpersia Posted November 25, 2010 Author Share Posted November 25, 2010 thanks ive made it work, Link to comment https://forums.phpfreaks.com/topic/219746-echo-out-user-id/#findComment-1139552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.