| | |
How to find the UserID on logging time
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.......
in my table 3 fields
" intUserID (autoincrement ,primarykey) , txtPassword ,txtUsername"
how to record the userID as session value. please.......
Hi...
inorder to record the sessions, do the following:
login.php
To access these stored sessions in other page..
page_user.php
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..
inorder to record the sessions, do the following:
login.php
php Syntax (Toggle Plain Text)
<?php session_start(); //most important line... as it marks the start of session //suppose user submits the login button and redirects to this page if($_POST['submit']=="submit") { //some condition above in if to detect user actually pressed login button //connect to database.. check username and password.. //when done... user authenticated.. $_SESSION['userid']=$row['intUserID']; //get this value from database $_SESSION['username']=$row['txtUsername']; } //thats it.. the userid and usrname stored in sessions ?>
To access these stored sessions in other page..
page_user.php
php Syntax (Toggle Plain Text)
<?php session_start(); //above line must on every page where you need to access the session value echo $_SESSION['userid']; echo $_SESSION['username']; ?>
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..
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 ...
PHP Syntax (Toggle Plain Text)
<?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['txtUsername'])) { $loginUsername=$_POST['txtUsername']; $password=$_POST['txtPassword']; $MM_fldUserAuthorization = "intAccessLevel"; $MM_redirectLoginSuccess = "home.php"; $MM_redirectLoginFailed = "index.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_nydata2, $nydata2); $LoginRS__query=sprintf("SELECT txtUserName, txtPassword, intAccessLevel FROM tblusers WHERE txtUserName='%s' AND txtPassword='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $nydata2) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'intAccessLevel'); //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?>
Last edited by vijaysoft1; Dec 15th, 2008 at 3:16 am.
•
•
Join Date: Apr 2008
Posts: 296
Reputation:
Solved Threads: 11
PHP Syntax (Toggle Plain Text)
$user_fname=$_SESSION['MM_Username']; $sql=mysql_query("SELECT * FROM table where user_fname='$user_fname'"); while( $row = mysql_fetch_array($sql)) { $user_fname=$row['user_fname']; $pass=$row['user_pass']; $user_id=$row['user_id']; $gender=$row['user_sex']; }
fetch sql result in array..from that you take the value of whatever you want...
PHP Syntax (Toggle Plain Text)
echo $user_id;//check data using echo
Last edited by Aamit; Dec 15th, 2008 at 7:00 am.
•
•
•
•
Change the column name according to your column id ...PHP Syntax (Toggle Plain Text)
$user_fname=$_SESSION['MM_Username']; $sql=mysql_query("SELECT * FROM table where user_fname='$user_fname'"); while( $row = mysql_fetch_array($sql)) { $user_fname=$row['user_fname']; $pass=$row['user_pass']; $user_id=$row['user_id']; $gender=$row['user_sex']; }
fetch sql result in array..from that you take the value of whatever you want...
PHP Syntax (Toggle Plain Text)
echo $user_id;//check data using echo
•
•
Join Date: Apr 2008
Posts: 296
Reputation:
Solved Threads: 11
In your query, you are not selecting userid
only
txtUserName, txtPassword, intAccessLevel FROM tblusers
select UserID
only
txtUserName, txtPassword, intAccessLevel FROM tblusers
select UserID
PHP Syntax (Toggle Plain Text)
<?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['txtUsername'])) { $loginUsername=$_POST['txtUsername']; $password=$_POST['txtPassword']; $MM_fldUserAuthorization = "intAccessLevel"; $MM_redirectLoginSuccess = "home.php"; $MM_redirectLoginFailed = "index.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_nydata2, $nydata2); $LoginRS__query=sprintf("SELECT txtUserName, txtPassword, intAccessLevel,UserID FROM tblusers WHERE txtUserName='%s' AND txtPassword='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $nydata2) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); while( $row = mysql_fetch_array($LoginRS)) { $user_fname=$row['txtUserName']; $pass=$row['txtPassword']; $user_id=$row['UserID']; echo $user_fname; echo $pass; echo $user_id; } if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'intAccessLevel'); //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?>
![]() |
Other Threads in the PHP Forum
- Previous Thread: Testing
- Next Thread: Help reload
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select send server sessions sms snippet soap source space speed sql static structure syntax system table tutorial up-to-date update upload url validation validator variable video web wordpress xml youtube





