Jump to content

Need help with URL Parameters


tdies

Recommended Posts

My name is Thad and I have a BPA project that is due in little more than a week. My assignment is to create a Social Networking site from scratch with two other guys in my group. They work on all of the XHTML and CSS and I am stuck (alone) doing all of the PHP (lucky me). Obviously I don't expect this project to be anything like Facebook or Myspace with my limited experience and one month to complete the project.

 

Anyways I ran into a little snag while trying to get user profiles implemented. I am trying to find a way that I can use URL parameters connected to one php file to display all of the user profiles.

 

For example, instead of making a separate file or folder for each user like so:

 

Query the database for the userid of the user and display the url like this:

 

I have poured through google searches trying to find a solution with no luck, what I do know is that somehow it is going to have to involve the $_GET variable if i'm not mistaken.

 

I don't know, I hope someone understands what I need to do and can provide me with a solution.

Link to comment
https://forums.phpfreaks.com/topic/192835-need-help-with-url-parameters/
Share on other sites

Well see im not using the userid to log the users in, when the user comes to the site they see a login form where they must input their email address and their password to log in.

 

In the mysql database the userid is an integer used to link the accounts table (containing the users authentication data including their email with an SHA1 Encrypted password hash) to the profiles table (which contains user information such as name, age, favorite books, favorite movies, etc)

 

What I need to be able to do is create a profile page for each user based upon the userid in the profiles table, then I could pull all of the data based upon that unique userid and display it on that usrs profile page.

 

For instance when I go to your profile on this forum it takes me to this page:

http://www.phpfreaks.com/forums/index.php?action=profile;u=53269

 

"u=53269" should be a unique id for you in the phpfreaks database, then somehow in that code it pulls all relevant data for you and displays it on your profile page.

ok lets' say we have file called userlist.php

//connection

$result=mysql_query("SELECT id FROM `profile` ORDER BY `id`");
while($row=mysql_fetch_assoc($result))
{
echo "<a href='profile.php?user=".$row['id']."' target='_blank'>".$row['name']."</a><br>";
}

 

no we need create another file profile.php where will display user data

//connection

$userid = intval($_GET['user']; //this comes from url profile.php?user=NUMBER

$result = "SELECT * FROM `profile` WHERE `id`=$userid LIMIT 1";
$row = mysql_fetch_assoc($result);

echo "<h1>".$row['name']."</h1>";
echo "E-Mail:".$row['email']."<br />";
echo "Post count:".$row['pcount']."<br />";
echo "Hoby:".$row['hoby']."<br />";
//etc.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.