Hi all, so I'm looking to make a social network style site, just to help me understand php so please don't say anything about reinventing the wheel.

I'm looking for a way that when a user clicks on a name in the member list that it sends them to profile.php?id= so that profile.php can use it to identify whose profile they are looking for and can load the data for the profile from a mysql table.

member list

<?php
mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db ("phplogin");
$result = mysql_query ("SELECT * FROM users WHERE username=enzo");
@$row = mysql_fetch_array($result);
$id = $row['id'];
echo '<a href="profile.php?id="$id">Enzo's Profile</a>';
?>

profile

$currentprofile = $_GET ['id'];
mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db ("phplogin");
$result = mysql_query ("SELECT * FROM users WHERE id=$currentprofile");
@$row = mysql_fetch_array($result);
echo $row['profileinfo'];

is it wise to keep the profile info and "about me" user input text in a mysql table?

someone needs to write a decent tutorial on profiles that are user editable, people want to try recreate facebook/myspace to see how it works, its not about reinventing anything.

thanks, enzo

Recommended Answers

All 4 Replies

echo '<a href="profile.php?id="$id">Enzo's Profile</a>';
?>

ive spotted the " after the = sign, wasnt supposed to be there but $id doesnt seem to contain anything?

echo '<a href="profile.php?id="$id">Enzo's Profile</a>';
?>

ive spotted the " after the = sign, wasnt supposed to be there but $id doesnt seem to contain anything?

If you're trying to get the value of $id in that string then you have to concatenate because you're using single quotes.

echo '<a href="profile.php?id=' . $id . '">Enzo's Profile</a>';

thanks for your reply shawn, i got it sorted,

<div id="apDiv12">
<?php
$connect = mysql_connect("localhost", "root", "") or die (mysql_error());
$connect;
mysql_select_db ("phplogin");
$result = mysql_query ("SELECT * FROM users WHERE username='jackflash'");
$row = mysql_fetch_array($result);
$id = $row['id'];
echo ('<a href=profile.php?id='.$id.'>Jack Flash</a>');
?>
</div>

someone needs to write a decent tutorial on profiles that are user editable, people want to try recreate facebook/myspace to see how it works, its not about reinventing anything.

thanks, enzo

As for this, if you're just using it as a learning experience then it should be just that. It's not a very good learning experience if you just follow someone else's tutorial. The point of recreating something is to learn from the reverse engineering of it.

"Hmm, they have user profiles what is a user profile though. Let's see, a user has a name, and a phone number and an email address. But, oh, look a user has an ID too, that's probably the unique key."

"User's have friends but how do they do that? Ahh, I see, it's really just a list of user ids that they are friends with. But... I know that just storing a list of IDs breaks normalization so they probably have a many-to-many relationship of users. That makes more sense..."

Stuff like that.


(As an aside, echo doesn't need () it's not a function it's a language construct)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.