Jump to content


Photo

Personal touch to site


  • Please log in to reply
3 replies to this topic

#1 dirty_student

dirty_student
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 March 2006 - 03:35 PM

Hi All,

Hope somebody can help... the problem is that i have created a log in page for my site using dreamweaver MX and php mysql everything works fine but i would like to display the firstname and surname of the user that has logged in on the next page. My database is set up that the username and password fields are in the same table as the data i want to display if you will

Student_Number
User_Name
Password
Surname
First_Name

if you can understand what i mean i would appriciate some help!!!!

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 10 March 2006 - 03:50 PM

welcome to the forums! hope we can help you out here.

if i understand what you're after, once someone successfully logs it, you ought to keep a session variable with their user_id (or even just their username) so that you can pull their information on any future pages they hit. once you do that, you can run a simple query at the top of the page pulling their information from the database. use it wherever you want on the rest of the page.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 dirty_student

dirty_student
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 March 2006 - 03:57 PM

yeah that sounds about right but how do i create the session can you explain? sry complete novice

steve

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 10 March 2006 - 04:21 PM

Well first off every page in your site needs to start with
session_start();
Even the login page. After they fill in there username and password, and are authenticated you store the username in a session. Here is some code I use once the user has entered his info

if(isset($_POST['username'])){
$username = $_POST['username'];
$password = md5($_POST['password']);
$getuser = "SELECT * from users WHERE username = '$username' AND password = '$password'";
  $result = mysql_query($getuser) or die (mysql_error());
    $r = mysql_fetch_array($result);
    $qualify = mysql_num_rows($result);
if($qualify > 0){
$_SESSION['username'] = $_POST['username'];
}

Now whenever you want to use the persons username you just reference the session id

echo "Hello $_SESSION['username'] welcome to my site";

Ray




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users