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.
[code=php]
<?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($sq l)
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_i n'] = true;
$_SESSION['username'] = $username;
// after login we move to the main page
header('Locatio n: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="#0 00000">
<tr>
<td width="150">Use r Name</td>
<td><input name="txtUserna me" type="text" id="txtUsername "></td>
</tr>
<tr>
<td width="150">Pas sword</td>
<td><input name="txtPasswo rd" type="password" id="txtPassword "></td>
</tr>
<tr>
<td width="150">&nb sp;</td>
<td>
<input type="submit" name="btnLogin" value="Login">
</div></td></tr>
</table>
</form>
</body>
</html>
[/code]
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.
[code=php]
<?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($sq l)
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_i n'] = true;
$_SESSION['username'] = $username;
// after login we move to the main page
header('Locatio n: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="#0 00000">
<tr>
<td width="150">Use r Name</td>
<td><input name="txtUserna me" type="text" id="txtUsername "></td>
</tr>
<tr>
<td width="150">Pas sword</td>
<td><input name="txtPasswo rd" type="password" id="txtPassword "></td>
</tr>
<tr>
<td width="150">&nb sp;</td>
<td>
<input type="submit" name="btnLogin" value="Login">
</div></td></tr>
</table>
</form>
</body>
</html>
[/code]
Originally posted by Ajaxrand
Comment