I have a website and on the homepage after the user logs in, I want a text line that says "Welcome, %26lt;username%26gt;, you currently have %26lt;points%26gt; Points!"! I don't know how to retrieve the members current points field or username field from the database. I know how to get it, but how do I write it to automatically get only the person that is currently logged in's information?
How do I show a users name after they login in php?
// here is a basic code
// code above for authentication
// if authenticated
session_start();
// $name could be queried from the database
$_SESSION["user"] = $name;
header("Location:home.php");
exit;
///////////////
// home.php
$myname = $_SESSION['user'];
echo $myname
// hope that helps
// -keith
Reply:Here's how I would do it:
First, get the username and points information from the database, and store it in variables, like so:
$username = %26lt;DATABASE STUFF HERE%26gt;
$points = %26lt;DATABASE STUFF HERE%26gt;
Then, all you need to do is show that information to the user:
print "Welcome, ".$username;
print ", you currently have ".$points."!";
Now, for the exact database stuff, if you need all the details, feel free to email me at alexvillmann@gmail.com because all the connection stuff is really to long to post here.
Hope this helps some,
Alex
Reply:By running a query with the where set to the user's id, you must carry this through every page they visit anyway to control the security. I hope you have set some security.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment