Building your own Myspace.com with PHP part IV: Presentation
In the previous tutorial we learned how to register a new user and how to create a login system with php sessions. With this done we can now move on to the users personal presentation page. So in this tutorial we will first go over how to display a presentation and then how to let the user edit his own page.
Pretty much everything of this will go in a file I have called members.php, let’s go over the file from top to bottom.
connect();
$query = "SELECT * FROM members WHERE username='$member'";
$result = $db->query($query);
$exists = mysql_num_rows($result); // Does the row exists?
if($exists !="0"){ // Presentation exists so display it
$rows = $db->fetchArray($result); // Get the profile from database
echo $rows["presentation"]."
";
//TODO: Display guestbook here
}
else
{
echo "That member does not exist";
}
}
?>
This code is fairly simple. Basically what it does is that it gets the variable id that is passed to the file as an argument (remember how the login function forwarded to this page in the previous tutorial?) and then checks to see if there is a user by that name in the database. If there is a match that users presentation is displayed on the page.
Next on the list of features to add is the possibility to edit the presentation.
if(isset($_GET["edit"])) // Edit profile
{
// First lets make sure the user is logged in
if(session_is_registered("username") && session_is_registered ("password") && $_SESSION["username"] == $_GET["edit"])
{
if(isset($_GET["update"]))
{
require_once("classes/DbConnector.php");
$member = $_GET["edit"];
$db = new DbConnector();
$db->connect();
$presentation = $_POST["presentation"];
$query = "UPDATE members SET presentation='$presentation' WHERE username='$member'";
$result = $db->query($query);
echo "Profile updated!";
}
else
{ // Display edit box
require_once("classes/DbConnector.php");
$member = $_GET["edit"];
$db = new DbConnector();
$db->connect();
$query = "SELECT * FROM members WHERE username='$member'";
$result = $db->query($query);
$rows = $db->fetchArray($result);
echo "
Edit your profile
";
}
}
}
If we now call members.php?edit=username an edit box will appear that allows the user to edit his presentation. When the edit form is submitted we update the database with the new presentation.
Next part: Friends and guestbook


Does anyone if the the edit profile, guestbook, list of friends and search is all in members.php. i cant tell
thanks