alwaysinit Posted October 4, 2006 Share Posted October 4, 2006 I have a musician community portal site. I'm trying to create 'one' PHP page that is used for all musician's profiles. Does anyone know what I should name this page to where it will function as everyone's profile page?(Can it be just "profiles.php"? Or do I need something more in the name to do that?Thanks again for the help guys Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/ Share on other sites More sharing options...
trq Posted October 4, 2006 Share Posted October 4, 2006 You can name it whatever you like but in order to display each memebers profile you will need to pass a reference to that user. eg;profiles.php?member=thorpewould display my profile. Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-103483 Share on other sites More sharing options...
alwaysinit Posted October 4, 2006 Author Share Posted October 4, 2006 Ok thanks, Now say I have "profiles.php?member=thorpe". How did your name get there? And how do I put "SallyAnne" Or "JoeSmith" in place of "thorpe"? Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-103487 Share on other sites More sharing options...
alwaysinit Posted October 4, 2006 Author Share Posted October 4, 2006 How would the "profile.php" page come to be renamed "profiles.php?member=thorpe". How did it get that way? Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-103518 Share on other sites More sharing options...
tippy_102 Posted October 4, 2006 Share Posted October 4, 2006 Here's the basics....[code]<a href='profiles.php?member=memberName'>memberName</a>[/code] Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-103546 Share on other sites More sharing options...
corbin Posted October 4, 2006 Share Posted October 4, 2006 [code=php:0]How would the "profile.php" page come to be renamed "profiles.php?member=thorpe". How did it get that way?[/code]Either you worded this oddly or you're fairly new. Its the same page with a different GET value...Simply by changing memebe= in your address bar, or by using the more sought after <a href..., you can gain the same effect. Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-103558 Share on other sites More sharing options...
alwaysinit Posted October 4, 2006 Author Share Posted October 4, 2006 Yes I'm new to coding(two months). Sorry if my questions seem odd and presented incorrectly. From your responses(tanx to all), this is what I now think:(1) I create the profiles.php page.(2) Use "<a href='profiles.php?member=memberName'>memberName</a>" in my site's search results?(I'm not sure where to use the (<a href))(3) In the "profiles.php" place "$_GET['member']" to show the page as that member's.(4) then start echoing result rowsDo I have all that right? If incorrect could someone show the correct sequence of events for showing 1000's of different profiles off the same page?[quote]Here's the basics....Code:<a href='profiles.php?member=memberName'>memberName</a>[/quote] Where does this link go?Thanks again Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-103586 Share on other sites More sharing options...
trq Posted October 4, 2006 Share Posted October 4, 2006 The whole process is database driven. You'll need a database table.[code]CREATE TABLE users ( id INT PRIMARY KEY, uname VARCHAR(80), hobby TEXT)[/code]This is a make believe example designed to store a users id, name and there hobbies. Lets pretend we had 3 users...[code]id name hobby--------------1 bob internet2 foo cooking3 mary music[/code]Ok.... now you'll need 2 pages. One (index.php) to display the links to your users profile, and Two (profiles.php) to display each users hobby in detail.index.php[code=php:0]<?php // connect to database $sql = "SELECT uname FROM users"; $result = mysql_query($sql); if ($result) { if (mysql_num_rows($result) > 0) { // here we loop through each member in the database while ($row = mysql_fetch_assoc($result)) { /// creating a link out of there uname, and passing there uname through the url. echo "<a href=\"profiles.php?member={$row['uname']}\">{$row['uname']}</a><br />"; } } else { echo "No users found"; } else { echo "Query failed ". mysql_error(); }?>[/code]profiles.php[code=php:0]<?php if (isset($_GET['member'])) { // connect to database. $sql = "SELECT uname, hobby FROM users WHERE uname = '{$_GET['member']}'"; $result = mysql_query($sql); if ($result) { if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result)); echo "The user {$row['uname']} enjoys the hobby {$row['hobby']}"; } else { echo "No user found by that name"; } else { echo "Query failed ".mysql_error(); } } else { echo "No member selected"; }?>[/code]Ive tried to keep these examples pretty simple. There isn't allot of html mixed in just to make things a little clearer. Hope it helps.ps; Take a look at [url=http://php.net/mysql_connect]mysql_connect[/url]() in the manual for examples on how to connect to the database. Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-103630 Share on other sites More sharing options...
alwaysinit Posted October 4, 2006 Author Share Posted October 4, 2006 Wow thorpe, that is phreakin' awesome. I could'nt have asked for more detail and example.You rock.I'll get to coding now and post back if I run into trouble.Thanks for your time and know-how. Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-103739 Share on other sites More sharing options...
Hydrian Posted September 2, 2012 Share Posted September 2, 2012 I get Parse error: syntax error, unexpected T_ELSE in /home/localhost/public_html/members/index.php on line 14 when i open the index.php Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-1374631 Share on other sites More sharing options...
ignace Posted September 2, 2012 Share Posted September 2, 2012 It's a made-up example to communicate a point. The code is untested and it's not advised to just copy-paste it and put it on your live website due to the gaping security holes in the code. If you take a look at the code for index.php you'll notice a missing } after "No users found!"; The same for profiles.php after "No user found by that name"; Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-1374632 Share on other sites More sharing options...
Christian F. Posted September 2, 2012 Share Posted September 2, 2012 Nitpicking a bit, but I'd written the code a bit differently for ease of readability. I'd check for error conditions first, and if found add a warning/error message and exit early. Now, since this isn't a function or included code, I can't really exit early from this, but that's easily fixable by separating logic and presentation. (Read more about it in the "HEADER ERRORS" thread stickied at the top of this section.) Now, as to how I'd written the code: function getMemberDetails ($username) { if (empty ($username)) { return "No member selected"; } // Create the query, and escape input to avoid SQL injections. $sql = "SELECT uname, hobby FROM users WHERE uname = '%s'"; $sql = sprintf ($sql, mysql_real_escape_string ($username)); $result = mysql_query ($sql); if (!$result) { // TODO: mysql_error () should/must be removed before putting the code into production! return "Query failed " . htmlspecialchars (mysql_error ()); } if (mysql_num_rows ($result) <= 0) { return "No user found by that name"; } return mysql_fetch_assoc ($result); } // Retrieve the user details, and check if it returned an array or string (error message). if ($userDetails = getMemberDetails ($_GET['member'])) { // Query succeeded, add completed message to output. Adding escaping to prevent HTML injections. $temp = 'The user %1$s enjoys the hobby %2$s'; $output = sprintf ($temp, htmlspecialchars ($userDetails['uname']), htmlspecialchars ($userDetails['hobby'])); } else { // Something failed, show error message. $output = $userDetails; } Note that I haven't validated $_GET['member'] in the code above, something which you definitely should be doing. Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-1374714 Share on other sites More sharing options...
trq Posted September 2, 2012 Share Posted September 2, 2012 Your seriously commenting on a six year old post? Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-1374737 Share on other sites More sharing options...
Christian F. Posted September 2, 2012 Share Posted September 2, 2012 Damn. Only checked the date on the last two replies. Sorry about that. Link to comment https://forums.phpfreaks.com/topic/22932-now-that-i-know-what-to-ask-here-goes/#findComment-1374739 Share on other sites More sharing options...
Recommended Posts