How to find the UserID on logging time

Reply

Join Date: Jun 2008
Posts: 65
Reputation: vijaysoft1 is an unknown quantity at this point 
Solved Threads: 0
vijaysoft1's Avatar
vijaysoft1 vijaysoft1 is offline Offline
Junior Poster in Training

How to find the UserID on logging time

 
0
  #1
Dec 14th, 2008
I trying to make small personal website in PHP + MYSQL . In my database there is a table named ' tblUsers ' . I am using this table for users Login .I displayed the username of the user after the login . But how to track the userID of the user .

in my table 3 fields

" intUserID (autoincrement ,primarykey) , txtPassword ,txtUsername"

how to record the userID as session value. please.......
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: How to find the UserID on logging time

 
0
  #2
Dec 14th, 2008
Hi...
inorder to record the sessions, do the following:

login.php
  1. <?php
  2. session_start();
  3. //most important line... as it marks the start of session
  4. //suppose user submits the login button and redirects to this page
  5. if($_POST['submit']=="submit")
  6. {
  7. //some condition above in if to detect user actually pressed login button
  8. //connect to database.. check username and password..
  9. //when done... user authenticated..
  10. $_SESSION['userid']=$row['intUserID']; //get this value from database
  11. $_SESSION['username']=$row['txtUsername'];
  12. }
  13. //thats it.. the userid and usrname stored in sessions
  14. ?>

To access these stored sessions in other page..

page_user.php

  1. <?php
  2. session_start();
  3. //above line must on every page where you need to access the session value
  4. echo $_SESSION['userid'];
  5. echo $_SESSION['username'];
  6.  
  7. ?>

Apart from the above example.. refer the session tutorials by searching them on google..

http://tizag.com/phpT - Refer sessions tutorial here.. easy and simple..
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 65
Reputation: vijaysoft1 is an unknown quantity at this point 
Solved Threads: 0
vijaysoft1's Avatar
vijaysoft1 vijaysoft1 is offline Offline
Junior Poster in Training

Re: How to find the UserID on logging time

 
0
  #3
Dec 15th, 2008
This is my dreamweavers code to find session variable and in this a session variable named ' MM_Username ' . And Using that i got the ' username' of the user , how to implement code to find ' UserID ' in to this please ...


  1. <?php
  2. // *** Validate request to login to this site.
  3. if (!isset($_SESSION)) {
  4. session_start();
  5. }
  6.  
  7. $loginFormAction = $_SERVER['PHP_SELF'];
  8. if (isset($_GET['accesscheck'])) {
  9. $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  10. }
  11.  
  12. if (isset($_POST['txtUsername'])) {
  13. $loginUsername=$_POST['txtUsername'];
  14. $password=$_POST['txtPassword'];
  15. $MM_fldUserAuthorization = "intAccessLevel";
  16. $MM_redirectLoginSuccess = "home.php";
  17. $MM_redirectLoginFailed = "index.php";
  18. $MM_redirecttoReferrer = false;
  19. mysql_select_db($database_nydata2, $nydata2);
  20.  
  21. $LoginRS__query=sprintf("SELECT txtUserName, txtPassword, intAccessLevel FROM tblusers WHERE txtUserName='%s' AND txtPassword='%s'",
  22. get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  23.  
  24. $LoginRS = mysql_query($LoginRS__query, $nydata2) or die(mysql_error());
  25. $loginFoundUser = mysql_num_rows($LoginRS);
  26. if ($loginFoundUser) {
  27.  
  28. $loginStrGroup = mysql_result($LoginRS,0,'intAccessLevel');
  29.  
  30.  
  31. //declare two session variables and assign them
  32. $_SESSION['MM_Username'] = $loginUsername;
  33. $_SESSION['MM_UserGroup'] = $loginStrGroup;
  34.  
  35.  
  36. if (isset($_SESSION['PrevUrl']) && false) {
  37. $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
  38. }
  39. header("Location: " . $MM_redirectLoginSuccess );
  40. }
  41. else {
  42. header("Location: ". $MM_redirectLoginFailed );
  43. }
  44. }
  45. ?>
Last edited by vijaysoft1; Dec 15th, 2008 at 3:16 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 65
Reputation: vijaysoft1 is an unknown quantity at this point 
Solved Threads: 0
vijaysoft1's Avatar
vijaysoft1 vijaysoft1 is offline Offline
Junior Poster in Training

Re: How to find the UserID on logging time

 
0
  #4
Dec 15th, 2008
pla reply.....
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: How to find the UserID on logging time

 
0
  #5
Dec 15th, 2008
  1. $user_fname=$_SESSION['MM_Username'];
  2. $sql=mysql_query("SELECT * FROM table where user_fname='$user_fname'");
  3. while( $row = mysql_fetch_array($sql))
  4. {
  5. $user_fname=$row['user_fname'];
  6. $pass=$row['user_pass'];
  7. $user_id=$row['user_id'];
  8. $gender=$row['user_sex'];
  9. }
Change the column name according to your column id ...
fetch sql result in array..from that you take the value of whatever you want...

  1. echo $user_id;//check data using echo
Last edited by Aamit; Dec 15th, 2008 at 7:00 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 65
Reputation: vijaysoft1 is an unknown quantity at this point 
Solved Threads: 0
vijaysoft1's Avatar
vijaysoft1 vijaysoft1 is offline Offline
Junior Poster in Training

Re: How to find the UserID on logging time

 
0
  #6
Dec 15th, 2008
Originally Posted by Aamit View Post
  1. $user_fname=$_SESSION['MM_Username'];
  2. $sql=mysql_query("SELECT * FROM table where user_fname='$user_fname'");
  3. while( $row = mysql_fetch_array($sql))
  4. {
  5. $user_fname=$row['user_fname'];
  6. $pass=$row['user_pass'];
  7. $user_id=$row['user_id'];
  8. $gender=$row['user_sex'];
  9. }
Change the column name according to your column id ...
fetch sql result in array..from that you take the value of whatever you want...

  1. echo $user_id;//check data using echo
this is not working in my Dreamweaver , please help me to correct . U checked it . please..........
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: How to find the UserID on logging time

 
0
  #7
Dec 15th, 2008
In your query, you are not selecting userid

only
txtUserName, txtPassword, intAccessLevel FROM tblusers

select UserID

  1. <?php
  2. // *** Validate request to login to this site.
  3. if (!isset($_SESSION)) {
  4. session_start();
  5. }
  6.  
  7. $loginFormAction = $_SERVER['PHP_SELF'];
  8. if (isset($_GET['accesscheck'])) {
  9. $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  10. }
  11.  
  12. if (isset($_POST['txtUsername'])) {
  13. $loginUsername=$_POST['txtUsername'];
  14. $password=$_POST['txtPassword'];
  15. $MM_fldUserAuthorization = "intAccessLevel";
  16. $MM_redirectLoginSuccess = "home.php";
  17. $MM_redirectLoginFailed = "index.php";
  18. $MM_redirecttoReferrer = false;
  19. mysql_select_db($database_nydata2, $nydata2);
  20.  
  21. $LoginRS__query=sprintf("SELECT txtUserName, txtPassword, intAccessLevel,UserID FROM tblusers WHERE txtUserName='%s' AND txtPassword='%s'",
  22. get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  23.  
  24. $LoginRS = mysql_query($LoginRS__query, $nydata2) or die(mysql_error());
  25. $loginFoundUser = mysql_num_rows($LoginRS);
  26. while( $row = mysql_fetch_array($LoginRS))
  27. {
  28. $user_fname=$row['txtUserName'];
  29. $pass=$row['txtPassword'];
  30. $user_id=$row['UserID'];
  31. echo $user_fname;
  32. echo $pass;
  33. echo $user_id;
  34. }
  35.  
  36.  
  37. if ($loginFoundUser) {
  38.  
  39. $loginStrGroup = mysql_result($LoginRS,0,'intAccessLevel');
  40.  
  41.  
  42. //declare two session variables and assign them
  43. $_SESSION['MM_Username'] = $loginUsername;
  44. $_SESSION['MM_UserGroup'] = $loginStrGroup;
  45.  
  46.  
  47. if (isset($_SESSION['PrevUrl']) && false) {
  48. $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
  49. }
  50. header("Location: " . $MM_redirectLoginSuccess );
  51. }
  52. else {
  53. header("Location: ". $MM_redirectLoginFailed );
  54. }
  55. }
  56. ?>
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 10
Reputation: flagbarton is an unknown quantity at this point 
Solved Threads: 0
flagbarton flagbarton is offline Offline
Newbie Poster

Re: How to find the UserID on logging time

 
0
  #8
Dec 15th, 2008
you are using code generated by dreamweaver, i suggest to create our own log in form since code generated by dreamweaver is not flexible.
try to experiment the code posted by sikka_varun
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC