display user data after login
Moderator: General Moderators
display user data after login
hello guys,
i have a site, and i want when the user login into the secure site shows <?php echo "Bienvenido, {$_SESSION['$Real Name]}"; ?> instead the username i want something like this Welcome, Joe Satriani instead Welcome, jsatch.
the code that i have for the login is this one:
<?php session_start();
//Connect to database from here
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//select the database | Change the name of database from here
mysql_select_db('aasala');
//get the posted values
$user_name=htmlspecialchars($_POST['user_name'],ENT_QUOTES);
$pass=md5($_POST['password']);
//now validating the username and password
$sql="SELECT user_name, password FROM tbl_user WHERE user_name='".$user_name."'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
//if username exists
if(mysql_num_rows($result)>0)
{
//compare the password
if(strcmp($row['password'],$pass)==0)
{
echo "yes";
//now set the session from here if needed and query the real name
$_SESSION['u_name']=$user_name;
}
else
echo "no";
}
else
echo "no"; //Invalid Login
?>
An the secure.php is this one
<?php session_start();
// if session is not set redirect the user
if(empty($_SESSION['u_name']))
header("Location:index.html");
//if logout then destroy the session and redirect the user
if(isset($_GET['logout']))
{
session_destroy();
header("Location:index.html");
}
?>
Here goes the html
i have a site, and i want when the user login into the secure site shows <?php echo "Bienvenido, {$_SESSION['$Real Name]}"; ?> instead the username i want something like this Welcome, Joe Satriani instead Welcome, jsatch.
the code that i have for the login is this one:
<?php session_start();
//Connect to database from here
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//select the database | Change the name of database from here
mysql_select_db('aasala');
//get the posted values
$user_name=htmlspecialchars($_POST['user_name'],ENT_QUOTES);
$pass=md5($_POST['password']);
//now validating the username and password
$sql="SELECT user_name, password FROM tbl_user WHERE user_name='".$user_name."'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
//if username exists
if(mysql_num_rows($result)>0)
{
//compare the password
if(strcmp($row['password'],$pass)==0)
{
echo "yes";
//now set the session from here if needed and query the real name
$_SESSION['u_name']=$user_name;
}
else
echo "no";
}
else
echo "no"; //Invalid Login
?>
An the secure.php is this one
<?php session_start();
// if session is not set redirect the user
if(empty($_SESSION['u_name']))
header("Location:index.html");
//if logout then destroy the session and redirect the user
if(isset($_GET['logout']))
{
session_destroy();
header("Location:index.html");
}
?>
Here goes the html
Re: display user data after login
I don't understand...
Re: display user data after login
I have a web application and I want that when users get into the secure site display the real name instead the username.
I have a mysql table with columns id, username, pswd, Name, Lastname.
These two files two files that i show down here:
the first one connect to the db called ajax_login.php
and the second is secure.php
I have a mysql table with columns id, username, pswd, Name, Lastname.
These two files two files that i show down here:
the first one connect to the db called ajax_login.php
and the second is secure.php
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: display user data after login
Do you know how to use queries with a database?
Do you know how to extract data from a query?
Do you know how to extract data from a query?
Re: display user data after login
if(isset($_POST['user_name'])){
$_SESSION['Real_Name']=$_POST['user_name'];
}else{
$_SESSION['Real_Name']='jsatch';
}
echo 'Welcome, '.$_SESSION['Real Name'].'.';
$_SESSION['Real_Name']=$_POST['user_name'];
}else{
$_SESSION['Real_Name']='jsatch';
}
echo 'Welcome, '.$_SESSION['Real Name'].'.';
Re: display user data after login
aceconcepts wrote:Do you know how to use queries with a database?
Do you know how to extract data from a query?
Yes but too many things to learn
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: display user data after login
Well when you fetch you result set from the query you can get your results by:
Make sense?
Code: Select all
$row = mysql_fetch_array($result);
//you can then specify different fields like this:
$username = $row['username'];
Re: display user data after login
Yes just use the log in details to do a query on the database for the real name of the user then throw that into a variable and place that onto the screen instead!
Re: display user data after login
nd3_2000 wrote:Yes just use the log in details to do a query on the database for the real name of the user then throw that into a variable and place that onto the screen instead!
thanks for your support i let you know when i get this works