... and what I need is a script that I can implement into my site
where when a logged in user goes to ../myacc.php the script will display
their user details that are in the database, and displays their row
according to a session that has their username which was set when they logged in.
First you need to add a new field to your users table called "username" which is typically different than their first and last name, otherwise how are you going to find the correct row in the database?
Once that's done, assuming all usernames are unique:
// Connect to MySQL... $conn = mysql_connect($hostname, $username, $password) or die("Connecting to MySQL failed"); mysql_select_db($database, $conn) or die("Selecting MySQL database failed");
// Run our query, see if session username exists in session field... $sql="select fname,lname,email from users where username='{$_SESSION['username']}' limit 1"; $result=mysql_query($sql,$conn);
// Parse our results into $data (as an associative array)... $data=mysql_fetch_assoc($result);
// If one row was found in the result set, username exists... if ($mysql_num_rows==1) { print "Welcome, {$data['fname']}{$data['lname']}, your E-Mail address is {$data['email']}"; } // Otherwise... else { print "Sorry, the username $username was not found in our database..."; }
Get the idea? Change the password and database stuff accordingly, and adjust the rest cosmetically as you see fit. On a side note I like to wrap {} around associative arrays in my source since it is syntaxically correct to use single quotes around key names, and avoid parsing errors. This method is much easier to write and read than: "blah".$data['keyname']."blah...";
Bookmarks