Showing user profile data on profile.php

Hi, need help displaying data from a user logged in such as the firstname and lastnane.

Here is my code:

the database table is named auth_users with username, firstname, lastname, password as fields.

I just want to show the first name and last name on the users profile.

[php]session_start();

// check session variable

if (isset($_SESSION[‘valid_user’]))
{

echo "Welcome to your profile “; echo $_SESSION[‘valid_user’]; echo " !!!”;

echo “First Name: Data from database”;
echo “Last Name: Data from database”; }

else { echo “not logged in”; }

[/php]

What do I do? I need a way to connect to the mysql database to grab data for the user that is currently logged in to show the firstname and lastname.

[php]
// localhost database Access Info

$host = ‘localhost’;
$user = ‘mysql_username’;
$pass = ‘mysql_password’;
$db = ‘mysql_databaseName’;

//connect to database
$conn = mysql_connect($host,$user,$pass) or die(“cant open the connection”);
mysql_select_db($db) or die(“could not select db”);

//run the query
$query = “SELECT firstname,lastname FROM auth_users WHERE username=’”.$_SESSION[‘valid_user’]."’";
$result = mysql_query($query) or die(“error in $query query” . mysql_error());

//get the results as an array
$row = mysql_fetch_assoc($result) or mysql_error());

// print firstname
echo $row[‘firstname’];

// print lastname
echo $row[‘lastname’];
[/php]

Thank you so much!! It worked perfectly!!

Sponsor our Newsletter | Privacy Policy | Terms of Service