SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Memberlist linking to profiles.

    Hello everyone.

    I'm pretty new to all of this so any help would be greatly appreciated but you may have to be a bit patient with me.

    So, the problem...

    This is the website I'm currently working on. There's not much on it but I'm not really designing it for a specific purpose, just to learn PHP really. You can use the username Test and password Test to access the site.

    So, I've created the profile page for each member and allowed them to update their details, that's all fine. However, I've got a memberlist and as you'll see, clicking on the member's name doesn't bring up their profile as it should.

    I've got the following code to bring up the profile;

    Code:
    <?
    $name = $cookie;
    
    $details = file_get_contents("Members/$cookie.txt");
    
    $details = explode("\n", $details);
    
    if ($details[2] == "") {$theiremail = "N/A";} else {$theiremail = $details[2];}
    if ($details[3] == "") {$theirage = "N/A";} else {$theirage = $details[3];}
    if ($details[4] == "") {$theirloc = "N/A";} else {$theirloc = $details[4];}
    if ($details[5] == "") {$theirweb = "N/A";} else {$theirweb = $details[5];}
    if ($details[6] == "") {$theirteam = "N/A";} else {$theirteam = $details[6];}
    
    ?>
    
    <html>
    
    <head>
    <link rel="stylesheet" type="text/css" href="stylesheet.css" />
    
    </head>
    
    <body>
    	<table style="border-collapse: collapse" border="1" bordercolor="#111111" align="center">
    	<tr class="links" align="center">
    	<td>
    <? echo "
    
    <u>Name:</u><br> $details[0]<br><br>
    <u>Email Address:</u><br>$theiremail <br>
    <br> <u>Age:</u><br> $theirage<br>
    <br><u>Location:</u><br> $theirloc<br>
    <br> <u>Favourite Website:</u><br>$theirweb";
    ?>
    
    	</td>
    	</tr>
    	</table>
    
    <br>
    
    <a href=index.php?page=editprofile>Update your details.</a>
    
    
    </body>
    
    </html>
    but this doesn't recognise the cookie so brings up the following error;

    Code:
    Warning: file_get_contents(Members/.txt) [function.file-get-contents]: failed to open stream: No such file or directory in /home/jaydioci/public_html/AJ/viewmember.php on line 6
    So I tried to rectify this by using the code I've used in previous pages to display data depending on cookies as so;

    Code:
    <? $cookie = $_COOKIE['username'];
    			if (!isset($cookie)) { echo "Welcome to AJ Online ";}
    			else if (isset($cookie)) {echo "Welcome back to AJ Online, $cookie.";} ?>
    However, when I use this code at the top of the above script, I simply get the data of the user logged in ie. If logged in as myself, AJ, every profile I click on displays the data of the user 'AJ', not the user of the profile of whom I am trying to access.

    I know I'm probably making a simple error but I just can't get my head around it.

    Any help would be greatly appreciated and if I haven't explained anything in enough detail, I'd be happy to go through it again in more detail.

    Thanks in advance for any help you can provide,

    Antony.

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You should pass the username through the url query param, ex. profile.php?username=test

    Then get it back in the script from $_GET['username']
    Saul

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this is a bit lazy and probably won't help me much but do you think you could possibly write that up for me in the form of a script because I don't really understand it. As I said, I'm a newbie so don't really have a full grasp on this yet.

    Cheers.

  4. #4
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The username is being run through the url query param as can be seen in a browser when you hover over one of the names in the memberlist. You can clearly see in the status bar (or whatever it is) that each name has it's individual link, exactly as it should be. I've changed my code to this;

    Code:
    $name = $_GET['username'];
    
    $details = file_get_contents("Members/$name.txt");
    But when I click on a user's name it's still not recognising the name of the user, saying that the directory doesn't exist.

    It seems so simple that it's too hard to do! Really frustrating...

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What exectly the error message is? Does the directory "Members" really exist?
    Saul

  6. #6
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not recognizing the $name var. See if this helps:
    PHP Code:
    $details file_get_contents("Members/".$name.".txt"); 

  7. #7
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon
    What exectly the error message is? Does the directory "Members" really exist?
    Yeah, the directory definately exists but for some reason, as said, the $name parameter isn't being recognised. I have an idea why, I will look into it and if that doesn't help I'll use your advice mudshark, cheers.

  8. #8
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Check if the request url is really correct.
    Saul

  9. #9
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've sorted it now. Just, as I suspected it would be, a stupid mistake.

    I took your advice, daemon, and used;

    Code:
    $_GET['username']
    However, when noticing that the link actually said viewmember.php?name=$name I had a brainwave and realised that what I should really be using is;

    Code:
    $_GET['name']
    I changed this earlier and it works now.

    Cheers for all of your help guys.

  10. #10
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to be a pain but I've got another question. I can't just have this list of members going on forever as people keep signing up. What I need is a sort of page number system with say, 5 members, on each page. Ie. Page 1 has 5 members on it, page 2 has the next 5 etc.

    Any ideas?

  11. #11
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This should give you an idea on how to code pagination.

    PHP Code:
    <?php 

    if(!isset($_GET['page'])){ 
        
    $page 1
    } else { 
        
    $page $_GET['page']; 


    $max_results '5';

    $from = (($page $max_results) - $max_results); 

    $sql "SELECT * FROM table ORDER BY id ASC LIMIT $from$max_results";

    $result mysql_query($sql); 
    while (
    $row mysql_fetch_array($result)) {
    $id $row['id'];


    ?>
     
    // echo data here

    <?php


    $total_results 
    mysql_result(mysql_query("SELECT COUNT(*) as Num FROM table"),0); 

    $total_pages ceil($total_results $max_results); 

    echo 
    "<center>";

    if(
    $page 1){ 
        
    $prev = ($page 1); 
        echo 
    "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Previous</a>&nbsp|&nbsp"


    for(
    $i 1$i <= $total_pages$i++){ 
        if((
    $page) == $i){ 
                echo 
    "$i&nbsp;"
            } else { 
                echo 
    "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a>&nbsp"
        } 


    if(
    $page $total_pages){ 
        
    $next = ($page 1); 
        echo 
    "&nbsp|&nbsp<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next</a>"
    }

    echo 
    "</center>";


    ?>

    hth

  12. #12
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for that, only problem being that I'm using flatfile, not MySQL. Cheers for the help though.

    I've kind of got it working but it's being a complete pain in the rear! I've got the system set up but it retrieves the data to be in the list from another file. Eg. My memberlist.php page collects data from the file members.txt. However, this method takes each line individually, including code, so I can't manage to integrate my profiles to the list which is the sole purpose of it?!?!

  13. #13
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh didnt realise you were using flat file .. I havnt had to much to do with it .. but im guessin using explode and counting the records with that code may work.


    Good luck


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •