Jump to content

Getting data linked to user


slj90

Recommended Posts

Hello, I am trying to create a page that shows the users details, the code gets these details by finding the username in the table and then displaying the other details, but i can't really get my head around how to get this to work..

 

I have a session:

<?php

session_start();

// Check if we have an authenticated user
if (!isset($_SESSION["authenticatedUser"]))
//if not re-direct to login page
{
$_SESSION["message"] = "Please Login";
header("Location: loginform.php");
}
else
{ 
//If authenticated then display page conetents
?>

 

And then the code I am using (which doesn't work) to get the other info by using the username stored in authenticatedUser

 

<?php

include ("connectionusers.php");
   
// (2)gather details of username sent 
$Username = $_GET['authenticatedUser'] ;
   
// (3)create query 
$query = "SELECT * FROM users WHERE authenticatedUser = $Username";

// (4) Run the query on the customer table through the connection
$result = mysql_query ($query);

// (5) print message with ID of inserted record    
if ($row = mysql_fetch_array($result)) 
{ 
print "Your account details:<br>"; 
print "<br><b>You are member number...</b>" . $row["ID"] . "<br>" ;
print "<br><b>Username: </b>" . $row["Username"] . "<br>"; 
print "<br><b>Email: </b>" . $row["Email"] .  "<br>"; 
print "<br><b>Password: </b>" . $row["Password"] . "<br>"; 
}

?>

 

I hope you understand what I am trying to do here and would appreciate any help you can give.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/185272-getting-data-linked-to-user/
Share on other sites

So your saying it should be..

 

<?php

include ("connectionusers.php");
   
// (2)gather details of CustomerID sent 
$Username = $_SESSION["authenticatedUser"] ;
   
// (3)create query 
$query = "SELECT * FROM users WHERE authenticatedUser = $Username";

// (4) Run the query on the customer table through the connection
$result = mysql_query ($query);

// (5) print message with ID of inserted record    
if ($row = mysql_fetch_array($result)) 
{ 
print "Your account details:<br>"; 
print "<br><b>You are member number...</b>" . $row["ID"] . "<br>" ;
print "<br><b>Username: </b>" . $row["Username"] . "<br>"; 
print "<br><b>Email: </b>" . $row["Email"] .  "<br>"; 
print "<br><b>Password: </b>" . $row["Password"] . "<br>"; 
}
?>

 

It still doesn't work. In the query line..

 

$query = "SELECT * FROM users WHERE authenticatedUser = $Username";

 

do I have the authenticatedUser and Username the right way round?

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.