1,105,556 Community Members

PHP: Visit other users?

Member Avatar
kaizokupuffball
Light Poster
39 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi!

Im currently trying to make a social website of a kind.
I got the login, registration, userpage, profile TINYMCE editor working.

But there is one thing im really struggling with, and that is;
How do i let other users visit other users?

When the user log's in, they're redirected to the user.php page.
I tried to just simply write user.php?id=6 in the url bar, but that did obviously not work, and i still was on my own profile page.

I don't really understand what i have to do either to get this working.
If anyone had the time and knowledge to help me out, i would really appreciate it!

Thx in advance!

Member Avatar
sv3tli0
Junior Poster in Training
81 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 18 [?]
Skill Endorsements: 0 [?]
 
0
 
user.php?id=6

to work you must make a coding in your page called
user.php
use $_GET["id"] (this will get id of the user you visit) and make a "SELECT" mysql_query to get this user info from your database and display it. :)

P.P> Here is sample:

<?php
include_once(YOURCONFIGfile.php);

if($_GET["id"]=="") { echo "ERROR: THERE IS NO SELECTED USER!"; die(); }
else
{
$html=""; //this will be our html code for output
$id = $_GET["id"];
$sql= "SELECT * FROM USERSTABLE WHERE id='".$id."'";
$res=mysql_query($sql);
while($row=myslq_fetch_array($res)){
$html.="Username: ".$row["username"]."<br>Email".$row["email"];
}
echo $html;
}
?>

This is only sample code.. it depends on your site and database structures, how it will look for you.

Member Avatar
sv3tli0
Junior Poster in Training
81 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 18 [?]
Skill Endorsements: 0 [?]
 
0
 

If you want a better sample please provide us with your database structure and how you include your config files (for database connection and etc..)

Member Avatar
kaizokupuffball
Light Poster
39 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Ahh, i see, i will take a look over the code and read about the $_GET function so i can understand it.
Thank you, i really appreciated it! :)

Member Avatar
kaizokupuffball
Light Poster
39 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I became a little confused when trying to understand the code with mine.
If you could take a quick look at my structure, i would be gratefull.

http://pastebay.com/137192
Password: mariuslikeris

Member Avatar
sv3tli0
Junior Poster in Training
81 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 18 [?]
Skill Endorsements: 0 [?]
 
0
 

If you use already user.php for personal page I think it will be best to create new page called users.php which to be your users view page.
Other way if you want to use the same user.php is to set current code to be when $_GET["id"]is equal to nothing

if($_GET["id"]=="") { current page code }
else { new code as the example which I gave you }

The $_GET[] is getting info from page url entered . its reading this way

page.php?STRING1=VALUE1&STRING2=VALUE2&STRING3=VALUE3

this url will provide you with gets like this :

$_GET["STRING1"] = VALUE1;
$_GET["STRING2"] = VALUE2;
$_GET["STRING3"] = VALUE3;

In inputs form this is claled method="get"
its good only if you use it for display pages. Its not good offer for login or other forms where you have protected data as password, mail or other personal data

Member Avatar
kaizokupuffball
Light Poster
39 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Ahh, i think i got it now!
Thank you so much for helping out!
:)

Question Answered as of 2 Years Ago by sv3tli0
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: