Page 1 of 1

display user data after login

Posted: Tue Aug 11, 2009 5:17 pm
by ralmaraz
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

Re: display user data after login

Posted: Tue Aug 11, 2009 5:22 pm
by jackpf
I don't understand...

Re: display user data after login

Posted: Tue Aug 11, 2009 5:44 pm
by ralmaraz
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

Re: display user data after login

Posted: Tue Aug 11, 2009 5:50 pm
by aceconcepts
Do you know how to use queries with a database?
Do you know how to extract data from a query?

Re: display user data after login

Posted: Tue Aug 11, 2009 5:54 pm
by Javof
if(isset($_POST['user_name'])){
$_SESSION['Real_Name']=$_POST['user_name'];
}else{
$_SESSION['Real_Name']='jsatch';
}
echo 'Welcome, '.$_SESSION['Real Name'].'.';

Re: display user data after login

Posted: Tue Aug 11, 2009 6:03 pm
by ralmaraz
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

Re: display user data after login

Posted: Tue Aug 11, 2009 6:20 pm
by aceconcepts
Well when you fetch you result set from the query you can get your results by:

Code: Select all

 
$row = mysql_fetch_array($result);
 
//you can then specify different fields like this:
$username = $row['username'];
 
Make sense?

Re: display user data after login

Posted: Wed Aug 12, 2009 3:40 am
by nd3_2000
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

Posted: Wed Aug 12, 2009 2:15 pm
by ralmaraz
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