To begin, create a new file if you havent got one already, and call it members.php
Now, you will want to check to make sure the user is logged in, so include your login_check.php file that we created earlier.
CODE
<?php
include 'login_check.php';
include 'login_check.php';
Now that we know that they are a member, lets get the user they are trying to view and set up an array of that users info.
CODE
$username = safe($_GET['username']);
if($username == '')
{
$username = safe($_COOKIE['username']);
}
$qry = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
$row = mysql_fetch_array($qry);
?>
With their info set into the array $row, we can now create a table in display their info.
CODE
Welcome to your member profile!
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr><td>
<?php
echo "Username: ".$username;
?></td></tr>
<br><br><tr><td>
<?php
if($row['show_email'] != 1) { // checks to see if the user allows their email to be shown, where '1' means they allow it to be shown
?>[Email Hidden]
<?php } else {
echo "Email: ".$row['email']; // if they allow it, it displays their email
}
?>
<br><br></tr></td><tr><td>
<?php
echo "Website: ".$row['website']; // displays the users website
?><br><br></tr></td><tr><td>
<?php
echo "Registration Date: ".$row['regdate']; // displays the users registration dats
?><br><br></tr></td><tr><td>
<?php
echo "Location: ".$row['location']; // displays the users location
?><br><br></tr></td></table>
<a href="/logout.php">Log Out</a>
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr><td>
<?php
echo "Username: ".$username;
?></td></tr>
<br><br><tr><td>
<?php
if($row['show_email'] != 1) { // checks to see if the user allows their email to be shown, where '1' means they allow it to be shown
?>[Email Hidden]
<?php } else {
echo "Email: ".$row['email']; // if they allow it, it displays their email
}
?>
<br><br></tr></td><tr><td>
<?php
echo "Website: ".$row['website']; // displays the users website
?><br><br></tr></td><tr><td>
<?php
echo "Registration Date: ".$row['regdate']; // displays the users registration dats
?><br><br></tr></td><tr><td>
<?php
echo "Location: ".$row['location']; // displays the users location
?><br><br></tr></td></table>
<a href="/logout.php">Log Out</a>
Now if you created the page correctly, this is what your members.php should look like:
CODE
<?php
include 'login_check.php';
$username = safe($_GET['username']);
if($username == '')
{
$username = safe($_COOKIE['username']);
}
$qry = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
$row = mysql_fetch_array($qry);
?>
Welcome to your member profile!
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr><td>
<?php
echo "Username: ".$username;
?></td></tr>
<br><br><tr><td>
<?php
if($row['show_email'] != 1) { // checks to see if the user allows their email to be shown, where '1' means they allow it to be shown
?>[Email Hidden]
<?php } else {
echo "Email: ".$row['email']; // if they allow it, it displays their email
}
?>
<br><br></tr></td><tr><td>
<?php
echo "Website: ".$row['website']; // displays the users website
?><br><br></tr></td><tr><td>
<?php
echo "Registration Date: ".$row['regdate']; // displays the users registration dats
?><br><br></tr></td><tr><td>
<?php
echo "Location: ".$row['location']; // displays the users location
?><br><br></tr></td></table>
<a href="/logout.php">Log Out</a>
include 'login_check.php';
$username = safe($_GET['username']);
if($username == '')
{
$username = safe($_COOKIE['username']);
}
$qry = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
$row = mysql_fetch_array($qry);
?>
Welcome to your member profile!
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr><td>
<?php
echo "Username: ".$username;
?></td></tr>
<br><br><tr><td>
<?php
if($row['show_email'] != 1) { // checks to see if the user allows their email to be shown, where '1' means they allow it to be shown
?>[Email Hidden]
<?php } else {
echo "Email: ".$row['email']; // if they allow it, it displays their email
}
?>
<br><br></tr></td><tr><td>
<?php
echo "Website: ".$row['website']; // displays the users website
?><br><br></tr></td><tr><td>
<?php
echo "Registration Date: ".$row['regdate']; // displays the users registration dats
?><br><br></tr></td><tr><td>
<?php
echo "Location: ".$row['location']; // displays the users location
?><br><br></tr></td></table>
<a href="/logout.php">Log Out</a>
Now, to have your users be able to go to this site, you will have to add a link to it in your index.php file.
So, add the following right above where you ask the logged in user to logout, like so:
CODE
If you would like to view your members page, please visit your <a href='/index.php?id=members'>Members Page</a>
That is it!! Now you have a table that will tell your user all the information that he has in the database, and will allow other users to view that persons profile!!
REMEMBER!!!!
on any link to your members site, you must have the code look like this:
CODE
<a href ="/index.php?id=members&username=DESIRED_USERNAME_HERE">Members only</a>
If you want the source files created in this tutorial, you can download them here: http://www.megaupload.com/?d=3NEWPUYC
If you want to see a working example, you can visit: test.city-scapes.net
Thank you all and good night!