Hi
I am using the following code to get users to enter their username and password, it is then checked and a new page is displayed with their username. My question is, how can I display the rest of their details from that session, I have googled and read many articles, but I am still not any futher forward, any help would be much appreciated. -
<?php
-
session_start();
-
$errorMessage = '';
-
if (isset($_POST['txtUsername']) && isset($_POST['txtPassword'])) {
-
include 'includes/config.php';
-
include 'includes/opendb.php';
-
-
$username = $_POST['txtUsername'];
-
$password = md5($_POST['txtPassword']);
-
-
// check if the user id and password combination exist in database
-
$sql = sprintf("SELECT username
-
FROM phpbb_users
-
WHERE username = '%s'
-
AND user_password = '%s'",$username,$password);
-
-
$result = mysql_query($sql)
-
or die('Query failed. ' . mysql_error());
-
if (mysql_num_rows($result) == 1) {
-
// the user id and password match,
-
// set the session
-
$_SESSION['db_is_logged_in'] = true;
-
$_SESSION['username'] = $username;
-
// after login we move to the main page
-
header('Location:main.php');
-
exit;
-
} else {
-
$errorMessage = 'Sorry, wrong user id / password';
-
}
-
-
include 'includes/closedb.php';
-
}
-
?>
-
-
<html>
-
<head>
-
<title>Basic Login</title>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-
</head>
-
<body>
-
<?php
-
include 'includes/header.php';
-
include 'includes/navbar.tpl';
-
if ($errorMessage != '')
-
?>
-
<p> <strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
-
-
<form method="post" name="frmLogin" id="frmLogin">
-
<table width="400" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#000000">
-
<tr>
-
<td width="150">User Name</td>
-
<td><input name="txtUsername" type="text" id="txtUsername"></td>
-
</tr>
-
<tr>
-
<td width="150">Password</td>
-
<td><input name="txtPassword" type="password" id="txtPassword"></td>
-
</tr>
-
<tr>
-
<td width="150"> </td>
-
<td>
-
<input type="submit" name="btnLogin" value="Login">
-
</div></td></tr>
-
</table>
-
-
</form>
-
</body>
-
</html>
-
Make use of the available formatting tags in the forum Use CODE tags around your code as appropriate: - [code]..code goes here..[ /code]
- [code=php] ..php code goes here.. [ /code]
- [code=c] ..C like code goes here.. [ /code]
- [code=html] ..html code goes here.. [ /html]
9 3545
Here is what is coded for the main page -
<?php
-
session_start();
-
include 'includes/header.php';
-
include 'includes/navbarout.tpl';
-
-
// is the one accessing this page logged in or not?
-
if (!isset($_SESSION['db_is_logged_in'])
-
|| $_SESSION['db_is_logged_in'] !== true) {
-
-
// not logged in, move to login page
-
header('Location: login.php');
-
exit;
-
}
-
-
echo sprintf("Welcome to the Revenge's members area, you are logged in as %s",$_SESSION['username']);
-
-
?>
-
ak1dnar 1,584
Recognized Expert Top Contributor Thread Title changed : Ajaxrand
From >>> Help for a n00b, whilst using sessions
To >>> User Login Script with Session
ak1dnar 1,584
Recognized Expert Top Contributor
You have created two session Variables so far,Here. -
// set the session
-
$_SESSION['db_is_logged_in'] = true;
-
$_SESSION['username'] = $username;
-
You Can use this $_SESSION['username'] to get the other records for the logged user.
Other_page.php -
session_start();
-
$Logged_in_user = $_SESSION['username'];
-
Now the the $Logged_in_user is here in this variable.
re-use it for any data manipulation,If this user name is a Qnique One
Thanks !
Thank you for the reply, I understand, what you are saying, however, how can extract the data from multiple tables with that one variable
kovik 1,044
Recognized Expert Top Contributor
Thank you for the reply, I understand, what you are saying, however, how can extract the data from multiple tables with that one variable
Depends on how the tables are related. Typically, all tables dealing with a user are somehow related by the user id. - SELECT `users`.`username`, `profiles`.`dateJoined` FROM `users` LEFT JOIN (`profiles`) ON (`profiles`.`userid` = `users`.`id`) WHERE `users`.`username` = $foo;
Understand now, however the query I used looks like the :
[PHP]$query = "SELECT phpbb_users.username, phpbb_users.user_from, phpbb_users.user_email, phpbb_ranks.rank_image
FROM phpbb_users
LEFT JOIN (phpbb_ranks)
ON (phpbb_users.user_rank = phpbb_ranks.rank_id)
WHERE phpbb_users.username = $Logged_in_user";[/PHP]
When I run it, this error appears, which I believe means that it's not connecting to the DB:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
If I change the variable $Logged_in_user to phpbb_users, everybodies details appear, so any ideas whats wrong with the query?
HOOAH, done it thank you for all your help, I understand now, I chnaged the query to
[PHP]$query = sprintf("SELECT phpbb_users.username, phpbb_users.user_from, phpbb_users.user_email, phpbb_ranks.rank_image
FROM phpbb_users
LEFT JOIN (phpbb_ranks) ON (phpbb_users.user_rank = phpbb_ranks.rank_id)
WHERE phpbb_users.username = '%s'",$Logged_in_user);[/PHP]
ak1dnar 1,584
Recognized Expert Top Contributor
ditch,
Since you have asked unrelated Question within the same thread, regarding PHP based calender I have to Split the thread. Please Read Why New Thraed Location:
Thanks ,
.
ak1dnar 1,584
Recognized Expert Top Contributor
Copied Contents from Splitted thread -Ajaxrand
By the way, the only problem with the first query was that you forgot the single quotes around the value.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: fr? |
last post by:
Hi,
i have a website , on wich users have to log in
credentials are checked against mysql db
some session vars are set during login for use somewhere else in the
code.
Is there a way to...
|
by: koolyio |
last post by:
Hey, could you please tell me what is wrong with my login script. I
just started learning php.
CODE:
login.php
<?
session_start();
header("Cache-Control: private");
?>
|
by: |
last post by:
Please help.
After a number of wrong turns and experiments I need advice on login
management system to secure our web pages without inconveniencing our
visitors or our internal staff.
What I...
|
by: Tom |
last post by:
Hi
I have a web application using asp.net and c#. User has to login to the application with his username and pwd. However, I do not allow other user uses the same username and pwd to login, i.e....
|
by: Tom |
last post by:
I hope someone can help me figure out what's going on here. I've
re-read the section on sessions at php.net and Googled this high and
low but I haven't found anything that quite explains my...
| |
by: tshad |
last post by:
I created a User Control that just does some VB code and doesn't have any
HTML in it.
Mainly it is an initialization piece that I want to put on all my pages. It
just has this code:
...
|
by: nasirmajor |
last post by:
dear all,
a simple quetion from still a bigginer in asp.net
i have a simple webpage with username and password which is linked with
database. now when user gives
his username and password and if...
|
by: underground |
last post by:
Hi, everyone I've been trying to figure out a way for a user to update there information. I'm using sections to identify the specific user..Here is the form
<?
include("include/session.php");...
|
by: satishknight |
last post by:
Hi,
Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
|
by: Gordon |
last post by:
I want to add a feature to a project I'm working on where i have
multiple users set up on my Postgres database with varying levels of
access. At the bare minimum there will be a login user who...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |