Page 1 of 2

PHP Profile Pages

Posted: Sun Nov 30, 2008 8:32 am
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 :)

Re: PHP Profile Pages

Posted: Sun Nov 30, 2008 1:41 pm
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?

Re: PHP Profile Pages

Posted: Sun Nov 30, 2008 2:59 pm
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.

Re: PHP Profile Pages

Posted: Tue Dec 02, 2008 10:28 am
by Paws
BUMP

Re: PHP Profile Pages

Posted: Tue Dec 02, 2008 11:02 am
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.

Re: PHP Profile Pages

Posted: Tue Dec 02, 2008 1:31 pm
by Paws
Ok, can you tell me what I should look into to make each page?

Re: PHP Profile Pages

Posted: Tue Dec 02, 2008 2:34 pm
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.

Re: PHP Profile Pages

Posted: Tue Dec 02, 2008 2:46 pm
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?

Re: PHP Profile Pages

Posted: Tue Dec 02, 2008 5:52 pm
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.

Re: PHP Profile Pages

Posted: Wed Dec 03, 2008 11:40 am
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...

Re: PHP Profile Pages

Posted: Wed Dec 03, 2008 12:25 pm
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>

Re: PHP Profile Pages

Posted: Thu Dec 04, 2008 3:35 pm
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"

Re: PHP Profile Pages

Posted: Thu Dec 04, 2008 3:43 pm
by Syntac
Missing a semicolon (line 12).

Re: PHP Profile Pages

Posted: Thu Dec 04, 2008 3:49 pm
by Paws
Now I get this error.

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


:crazy:

Re: PHP Profile Pages

Posted: Thu Dec 04, 2008 4:11 pm
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>