Jump to content

Recommended Posts

Hey,

I've searched google for the last week looking for something to help me create a Member Profile page that is viewable by other members of the site,

 

i have just the basic register and login stuff which is all working propoerly,

 

I would just like to know if someone would be able to post the code to put on the Member profile page.

 

i have each registered members name linked to  index.php?page=mem/memprof&id=$id

i have registration generating Unique ids..

 

i'm only new to the whole web-developeing thing so if there is more information that u request to be able to help me out please leave a reply.

 

Any help is much appreciated.

Thank you for reading.

 

EDIT: didnt type the link for the members properly. fixed now

 

Link to comment
https://forums.phpfreaks.com/topic/71257-solved-member-profiles/
Share on other sites

Now all you need to do is add a query to the profile page that gets info from the database according to whos ID is in the URL.

 

<?php

$id = mysql_real_escape_string($_GET['id']);

$query = "SELECT * FROM members WHERE memberID='$id'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);

//Now echo their information
//You will need to replace inside of $row array with your db field names
echo $row['col1'].'<br>';
echo $row['col2'].'<br>';
echo $row['col3'].'<br>';
echo $row['col4'].'<br>';

?>

query the db like,

 

<?php
$sql = 'SELECT * FROM `member_table` WHERE id = "'. $id .'"';
$sqlresult = mysql_query($sql);
while ($row = mysql_fetch_assoc($sqlresult)) {
// Stuff
}
?>

 

If you haven't done so, create a table (change member_table to the name of this table). In it, put fields like, 'memberid', 'membername', 'memberemail', 'memberpassword' (note, on the last one, I wouldn't go around showing this on a profile page..). Then, change // Stuff to:

 

?>

//

<?php

 

and replace // with your page code. Whenever you want to echo something, put <?php echo $row['field name']; ?>

 

 

Edit: Aaw :(

Now all you need to do is add a query to the profile page that gets info from the database according to whos ID is in the URL.

 

Sorry, i dont mean to be a pain but, how would i do that...

when i click the name the url shows as index.php?page=mem/memprof&id=    <--- if i type 1 in there.. it comes up with the person whos id is number 1's information... but im unsure as to how i set it to get that persons id by itself.

 

Thanks for your help.

Now all you need to do is add a query to the profile page that gets info from the database according to whos ID is in the URL.

 

<?php

$id = mysql_real_escape_string($_GET['id']);

$query = "SELECT * FROM members WHERE memberID='$id'";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);

//Now echo their information
//You will need to replace inside of $row array with your db field names
echo $row['col1'].'<br>';
echo $row['col2'].'<br>';
echo $row['col3'].'<br>';
echo $row['col4'].'<br>';

?>

 

Look, I gave you the code showing you how to do it.

You need two scripts. One to view a list of users, and another to list there details. Example...

 

members.php

<?php

  // connect to db

  $sql = "SELECT id, uname FROM users";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_assoc($result)) {
        echo "<a href='profile.php?id={$row['id']}'>{$row['uname']}</a><br />";
      }
    }
  }

?>

 

Then in profile.php.

<?php

  // connect to db

  if (isset($_GET['id'])) {
    $id = mysql_real_escape_string($_GET['id']);
    $sql = "SELECT id, uname, moredetail, email FROM users WHERE memberID = '$id' LIMIT 1";
    if ($result = mysql_query($sql)) {
      if (mysql_num_rows($result)) {
        $row = mysql_fetch_assoc($result);
        echo $row['id'].'<br />';
        echo $row['uname'].'<br />';
        echo $row['moredetail'].'<br />';
        echo $row['email'].'<br />';
      }
    }
  }

?>

:D it works now,

thank you to everyone who replied :) your help is muchly appreciated.

 

Now, onto another question :)  (very sorry, im really new to php)

 

How would i make a comment system from scratch to go in the profiles.

can anyone link me to a tutorial? or post a tutorial? :)

 

and, if its possible to make it like..

 

(USER NUMBER 1's profile) --------- (PERSON POSTS IN UNSER NUMBER 1's PROFILE)

                                        |

(PERSONS POST SHOWS UP IN USER NUMBER 1's PROFILE ONLY)

 

 

 

 

(USER NUMBER 2's profile) --------- (PERSON POSTS IN UNSER NUMBER 2's PROFILE)

                                        |

(PERSONS POST SHOWS UP IN USER NUMBER 2's PROFILE ONLY)

 

 

 

sorry bout the bad diagram hehe.

 

basically like a different comment box for each profile that shows only messages that were posted while in that persons profile.

and if its possible for that to be run off a single table or maybe 2.

 

 

if you can't understand what i mean ill try to explain it more.

Thank you.

 

A comment system is really easy, I think the issue is.. you dont know php or mysql therefor a tutorial will be of no real use as you need to understand whats happening

 

a comment system

 

1: a database that has the following fields in theory

 

USERID | POSTERID | TIMESTAMP | COMMENT

 

2: A page with a simple form to submit to php and write to mysql

 

3: a page to pull out the info from MYSQL

 

No tutorial required. If you want to add such features you need to know php/mysql to an intermediate level

Sorry if my little knowledge of php is starting to get annoying but.

 

i've created a comment system which puts a comment box in each persons profile as they register on my website.

but say if i put a comment in user no.1's profile.. it shows up in every comment box in every profile.

 

how would i fix this?

 

Thanks.

Averice

You are using PHP right?

 

And a mysql database?

 

I think you are doing this statically... huh?

 

If you have a comment system comments will be stored in a database. Each comment in the database will have a unique identifier, preferably the members ID or username

 

When you load there profile, you pull out comments that match there ID/USERNAME only

 

Seriously, it sounds like your fighting a loosing battle with all of this, its only easy if you have firm php/mysql experience. I suppose its a good way to learn though :)

my "postcomment" form posts the  Posterid  and the Comment... i need to know the code to post the Username of the persons profile i am viewing.. say i am viewing the Profile of Averice  how do i get the name of the persons profile im viewing (averice)  to be posted into the Userid section of my table.

 

also how would i order all the comments in the table to post only the comments where the userid matches the users profile i am viewing.

 

Thanks.

 

(EDIT): yea im using php and mysql.

www.site.com/profile.php?user=bollox

 

//mysql stuff

$query = "SELECT * FROM comments WHERE user = '$_GET[user]'";

$doquery = mysql_query($query);

 

while ($data = mysql_fetch_array($doquery)) {

echo "$data[user] - $data[comment]<BR>";

}

 

That assumes in your comments table the username field is called user and the comments field is called comment

 

That will pull out all comments for the username bollox

 

The username is passed to the mysql via $_GET which pulls it out from the URL, as you can see

 

Does this make sense? Can you do this? If not, look in the yellow pages for an intermediate php/mysql developer hehe

yes, i get it (sorta ^^).

 

But how do i put the username from the URL into the table?

 

would it be:

$query = "SELECT * FROM comments WHERE user = '$_GET[user]'";

$doquery = mysql_query($query);

-----SOME string thing here------------

 

$something = $_POST[user]

 

$comment = $_POST[usercomment]

 

 

$SQL = "INSERT * INTO comments (user, comment, posterid) VALUES ('$something','$comment','$username')";

$result = mysql_query($SQL)or die("fdgdsfgfdsG");

 

 

 

yer i think i know but i dont think i kno, try not to laugh if that code is way off :D

 

wait. forget the:

 

$query = "SELECT * FROM comments WHERE user = '$_GET[user]'";

$doquery = mysql_query($query);

-----SOME string thing here------------

 

$something = $_POST[user]

 

$comment = $_POST[usercomment]

 

 

$SQL = "INSERT * INTO comments (user, comment, posterid) VALUES ('$something','$comment','$username')";

$result = mysql_query($SQL)or die("fdgdsfgfdsG");

 

i relized its not in the comments table to be able to pull it out T_T

 

back to my question.

I would like to know, how do i get the username from the: www.mysite.com/profile.php?user=bollox  i.e. bollox is ther username i want.

 

how do i get that username. to be inserted into the userid section of my table so that only comments made whilest viewing that persons profile will be visible only on that persons profile.

 

im not sure if the way to do this was in jaymc's code.. the code i got from jaymc works fine. except, there is no userid to select the comments from. thus every comment made still shows up in every profile comment box.

How do you get the username from that url? www.site.com/index.php?username=beanbangers&name=PeterSmith

 

$username $_GET[username]; // this will echo beanbangers. $_GET is used to pull things from a URL

$name $_GET[name]; // this will echo PeterSmith

 

 

You need to structure your database with a primary key

 

Most people have a unique ID, this will be, the members ID

 

for instance, on this forum, aswell as our usernames, we all have IDS

 

Thats all this forum is arsed about when digging out our details. Our username is essentually just a display name

 

So, if you wanted to view all of my posts/topics, this forum will say

 

"Hey, I want to find all posts made by jaymc, I know his member ID is 2342 so I'll search the posts tables and pull out all matches where the ID for the post row is 2342"

 

So, in essance, your comments table must have a unique Identifier, somethnig to search by, AKA WHERE = user = 'jaymc'

 

or

 

WHERE userid = '2342'

 

If you can do that, you will get back all results only for that user

 

Ammend your table, add another field...

 

You keep going on about how do you get there username into the table..

 

Well, there username or userid should be in a SESSION or a COOKIE

 

Can you tell us all the fields your table has

 

P.S - When I write out code for you to use its not a script, its just an example or a dummy script

 

You will deffinately need to ammend it to work the way you want it, esecpecially when dealing with your own tables and fields etc

My Table Has:

 

Userid <--- i want to fill this with the name of the persons profile in which they are viewing aka  www.thegamespage.net/index.php?page=member/meminfo&id=Averice   

id <--- unique id for the comments made. (so i can order them from latest to earliest)

Username <--- posts the username of the person who posted the comment

Comment <---- the comment of the person.

 

 

the comment box shows as

 

Poster: Username <--- name of the person who submitted the comment. <---- works fine right now

Comment: <--- the comment of the person. <--- works

 

i want it as if somebody was viewing My Profile. and they decided to leave a comment. the comment they posted while viewing my profile would only be displayed in my profile.

 

Whilst if somebody posted in www.thegamespage.net/index.php?page=member/meminfo&id=Danglies    profile. the comment they posted while viewing Danglies profile would only be visible viewing Danglies profile. 

ok well. i didn't wanna post my code because i know its probably all wrong. i will probably get flamed about "security risks" and other stuff, yea its good that your pointing out stuff to me but i think my code might be like really bad so i dont know if u guys will laught at it/flame at it or help me with it :D  that is why i was scared to post my code. but seeing as i got no other option if i want this to work ill have to show u my code.

 

This is my code where the person inputs there comment.

<?php
session_start();
	include ("connect.php");
if (isset($_SESSION['username']))
	{
	include ("component.php");
	}
	else
	{
	die("You are not logged in");
	header("Location: index.php");
	}
?>
				<div id="right">
<div class="box_wrap">
<div class="box_head"><span style="color:#00FF00;">Post</span></div>
<div class="box_foot">
<center>
<form method="post" action="index.php?page=regiscom">
<table width='198' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <th align='left' colspan="2" scope="col">Comment</th>
  </tr>
  <tr>
    <th align='left' width="150" scope="row">Post:</th>
    <td align='left'><input width="100px" name="com" type="text" id="com" /></td>
  </tr>
  <tr>
    <th align='left' scope="row"></th>
    <td align='left'><input name="username" type="hidden" id="username" values="$user" /></td>
  </tr>
<tr>
<th align='left' scope="row"></th>
<td align='left'><input name="userid" type="hidden" id="userid" values="<?php $_GET[username]; ?>" />
  <tr>
    <th align='left' colspan="2" scope="row"><input name="reg" type="submit" id="reg" value="Post" />
    <input type="reset" name="Reset" value="Clear" /></th>
  </tr>
</table>
</form>
</center>

 

This is the code where the comment input posts to mysql

						    <div id="content">
					<div id="middle">
					 <div id="middle_title"><span style="color:#00FF00;">Posting....</span></div>
					  <div-id="middle_content">
<center>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th scope="col"><?php

$comment=$_POST['com'];

$userid=$_POST['userid'];

$id = mysql_insert_id();
$SQL = "INSERT into comdb (userid, id, username, comment) VALUES ('$userid','$id','$user','$comment')";
mysql_query($SQL) or die("could not Post Comment");


       print "<center>";

      

print "posting successful.<br>";

      print "Click here to <A href='index.php'>Home</a>";

?></th>
  </tr>
</table>
</center>
					</div>
					  </div>

 

This is the code that shows the Comments in the profile

				<div id="right">
<div class="box_wrap">
<div class="box_head"><span style="color:#00FF00;">Comments</span></div>
<div class="box_foot">
<div style=" width:198px; height:280px; overflow:auto;">
<table width="198" height="400" scrolling="yes">
<tr>
<td><?php
$query = "SELECT * FROM comdb WHERE userid = '$username $_GET[id]' ORDER BY id DESC";
$doquery = mysql_query($query);

while ($data = mysql_fetch_array($doquery)) {
echo "<center>Poster: <a href=index.php?page=member/meminfo&id=$data[username]>$data[username]</a><br> Comment: $data[comment]<BR></center>";
}
?></td>
</tr>
</table>
</div>
					</div>
					  </div>
<br>

 

Its probably all wrong and to far to be fixed.. but hey atleast ill find out now or never eh? :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.