display user data after login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ralmaraz
Forum Newbie
Posts: 6
Joined: Wed Jun 24, 2009 11:56 am

display user data after login

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: display user data after login

Post by jackpf »

I don't understand...
ralmaraz
Forum Newbie
Posts: 6
Joined: Wed Jun 24, 2009 11:56 am

Re: display user data after login

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: display user data after login

Post by aceconcepts »

Do you know how to use queries with a database?
Do you know how to extract data from a query?
User avatar
Javof
Forum Newbie
Posts: 1
Joined: Tue Aug 11, 2009 5:50 pm

Re: display user data after login

Post by Javof »

if(isset($_POST['user_name'])){
$_SESSION['Real_Name']=$_POST['user_name'];
}else{
$_SESSION['Real_Name']='jsatch';
}
echo 'Welcome, '.$_SESSION['Real Name'].'.';
ralmaraz
Forum Newbie
Posts: 6
Joined: Wed Jun 24, 2009 11:56 am

Re: display user data after login

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: display user data after login

Post 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?
nd3_2000
Forum Newbie
Posts: 4
Joined: Wed Aug 12, 2009 3:39 am

Re: display user data after login

Post 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!
ralmaraz
Forum Newbie
Posts: 6
Joined: Wed Jun 24, 2009 11:56 am

Re: display user data after login

Post 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
Post Reply