PHP Profile Pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Paws
Forum Newbie
Posts: 15
Joined: Sun Nov 30, 2008 8:26 am

PHP Profile Pages

Post by Paws »

Hey,

Well I want to add some of my own PHP profile pages. I started learning PHP less then a week ago so I know some basics but i'm not that good. I don't really want free scripts from anyone. But i'd like to know what pages I need to create, what PHP codes i'll need to use and look up and how hard it'll be to create.

Thanks :)
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: PHP Profile Pages

Post by omniuni »

Can you be a little more specific? What do you mean "profile pages"? You mean like you want to make a social networking website, or you just want a personal web page?
Paws
Forum Newbie
Posts: 15
Joined: Sun Nov 30, 2008 8:26 am

Re: PHP Profile Pages

Post by Paws »

I don't want it to be social networking, but I want users to have an option of making their own pages with infomation about them selfs.
Paws
Forum Newbie
Posts: 15
Joined: Sun Nov 30, 2008 8:26 am

Re: PHP Profile Pages

Post by Paws »

BUMP
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Re: PHP Profile Pages

Post by Cirdan »

Well, you would want a registration page where they enter the information. Another page that displays their profile based on their name or id. Then you would need to setup a MySQL database & table to store all the data. You might also want to have a login system. It shouldn't be too hard.
Paws
Forum Newbie
Posts: 15
Joined: Sun Nov 30, 2008 8:26 am

Re: PHP Profile Pages

Post by Paws »

Ok, can you tell me what I should look into to make each page?
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Re: PHP Profile Pages

Post by Cirdan »

The only major thing would be interacting with the database, and if you do a login system you would need to learn about sessions.
Paws
Forum Newbie
Posts: 15
Joined: Sun Nov 30, 2008 8:26 am

Re: PHP Profile Pages

Post by Paws »

Ok, what tables would I need in the database?

I want a page of users, with links to their own pages.

And then a table displaying the usernames and all their information?
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Re: PHP Profile Pages

Post by Cirdan »

You would just need to create one table to store all the user data. Then you generate the pages based on that data. You generate the links to the profiles based on the usernames like:

profile.php?user=CoolDude101

So you just loop through the rows in the database generating links using the user's username. Then on the profile page you select the row with the username, then use that data to generate a page.
Paws
Forum Newbie
Posts: 15
Joined: Sun Nov 30, 2008 8:26 am

Re: PHP Profile Pages

Post by Paws »

Cirdan wrote:You would just need to create one table to store all the user data. Then you generate the pages based on that data. You generate the links to the profiles based on the usernames like:

profile.php?user=CoolDude101

So you just loop through the rows in the database generating links using the user's username. Then on the profile page you select the row with the username, then use that data to generate a page.
How would I generate links like that?

Sorry I am really bad at this...
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Re: PHP Profile Pages

Post by Cirdan »

After you get a list of usernames from the databse, you just loop through the rows that you retrieved and do something like:

echo "<a href='profile.php?user=".$username."'>" .$username."</a>"

which would turn into

<a href='profile.php?user=CoolDude101'>CoolDude101</a>
Paws
Forum Newbie
Posts: 15
Joined: Sun Nov 30, 2008 8:26 am

Re: PHP Profile Pages

Post by Paws »

Ok I have 2 files;

Database.php

Code: Select all

<?php
 
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name="Persons"; // Table name 
 
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
 
?>
And the Index

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Profile</title>
</head>
 
<body>
 
<?php
 
include ('database.php')
 
$result = mysql_query('SELECT * FROM `Persons`);
echo = "$results";
 
?>
 
</body>
</html>
 

And I get this error: "Parse error: parse error, unexpected T_VARIABLE in /home/www/mydomain.com/profile/index.php on line 14"
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: PHP Profile Pages

Post by Syntac »

Missing a semicolon (line 12).
Paws
Forum Newbie
Posts: 15
Joined: Sun Nov 30, 2008 8:26 am

Re: PHP Profile Pages

Post by Paws »

Now I get this error.

Parse error: parse error, unexpected $ in /home/www/mydomain.com/profile/index.php on line 20


:crazy:
guygk
Forum Newbie
Posts: 9
Joined: Thu Dec 04, 2008 4:06 pm

Re: PHP Profile Pages

Post by guygk »

Code: Select all

<?php
$host="localhost"; // Host name
$username=NULL; // Mysql username
$password=NULL; // Mysql password
$db_name=NULL; // Database name
$tbl_name="Persons"; // Table name
 
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Profile</title>
</head>
<body>
<?php
include ('database.php');
 
$result = mysql_query("SELECT * FROM `Persons`;") or die(mysql_error());
// before you echo result you also need to evaluate result that comes from call to mysql_query()
// read more at: http://lt.php.net/mysql_fetch_row
// echo $result;
?>
</body>
</html>
Post Reply