runnerjp Posted May 9, 2008 Share Posted May 9, 2008 how can i make it so friends can add friends on my profile site?? Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/ Share on other sites More sharing options...
micah1701 Posted May 9, 2008 Share Posted May 9, 2008 how is it that you have over 1,000 posts on this site and still managed to post such a poorly worded question? Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536945 Share on other sites More sharing options...
ohdang888 Posted May 9, 2008 Share Posted May 9, 2008 not to mention that the friends feature is by far the most simple part of a social network. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536949 Share on other sites More sharing options...
runnerjp Posted May 9, 2008 Author Share Posted May 9, 2008 ok ok lol i want to do this,,, sure you have all used myspace,facebook or some social network well i want it so if you are a a friend of someone on a profile site... you can add them and they will be in your list of friends... this way they are the only 1ns allowed to see your profile and post on your comment box. simplist .. i cant get my head round it... how do i get the other users id?? and once i have this how would i post them into db my_id | friends_ids 1 2,3 2 2 Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536953 Share on other sites More sharing options...
micmania1 Posted May 9, 2008 Share Posted May 9, 2008 If your going to give simple descriptions, your going to get simple answers. Use PHP & MySQL. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536956 Share on other sites More sharing options...
ohdang888 Posted May 9, 2008 Share Posted May 9, 2008 yes we all know what you're trying to do..... we're just wondering why someone with 1000 posts doesn't know this.....odd.... you would create a new row for each relantionship id -- uid1 --- uid2 1 7 3 2 7 8 3 7 4 Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536959 Share on other sites More sharing options...
ohdang888 Posted May 9, 2008 Share Posted May 9, 2008 wait... are tyou asking how do you get the user ids??? ok this is not right. Either you've spammed a million posts, or you've gotten the password of anyother user and using that... selecting data is the most basic task you can do in mysql.... Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536960 Share on other sites More sharing options...
radar Posted May 9, 2008 Share Posted May 9, 2008 Hey he might have 1,000 posts but that doesnt mean he knows everything about PHP. Perhaps this is a new site that he's working on and is trying to do things he's never had any experience with. Now I myself have never done anything like this either though given time I don't think it would be too hard to figure out. I'm sure one of you may have some real experience with it and can help get him on the right track instead of complaining that he doesnt know it because he has more posts than you. Utlimately I would think that you'd have a few queries to handle this... First one is to select uid from users where username = username, to get the user id of the user to be added. Next one, insert it into say user_friends or something.... you'll be needing 2 id's for this.. the main id and the friends id... Then on the main page do a query from that as well -- you select all the information of the profile to get the uid of that member, and you have the viewers member id in a session (or if they are a guest it's not set)... then you do something like.. select * from users_friends where uid = uid & fid = $_SESSION['uid'] limit 1; then if its blank show an error saying they need to be friends of this person... and if they are in there, it will show the page. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536969 Share on other sites More sharing options...
micmania1 Posted May 9, 2008 Share Posted May 9, 2008 He's asking us to create his website for him... http://www.phpfreaks.com/forums/index.php/topic,196347.0.html This is a help section, not a slave section. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536973 Share on other sites More sharing options...
radar Posted May 9, 2008 Share Posted May 9, 2008 No where he did he say 'make my site for me'... He is only asking for help. Sure he is asking for a lot of different things, but hey give him some basic answers like I did above, some ideas and help him get on the right track.. no need to make all the scripts for him, just give him a boost with some basic ideas... that is being helpful, criticizing his PHP skills and his post count is not. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536977 Share on other sites More sharing options...
DarkWater Posted May 9, 2008 Share Posted May 9, 2008 Straight off of my site: $query = "SELECT u.* FROM friends AS f INNER JOIN users AS u ON f.friend_id = u.user_id WHERE f.user_id = '{$_SESSION['user_id']}' AND f.accepted = 0"; Table named friends and table named users. Users contains the user info. Friends is setup like this: user_id friend_id 4 5 4 6 5 9 Like that. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536989 Share on other sites More sharing options...
runnerjp Posted May 9, 2008 Author Share Posted May 9, 2008 hey..ok some harsh people on here... thaks radar and darkwater ok i all i need to know is how would i go about getting the friends id... would it be from the url?? and also the best way to store it in the database i never asked to write the code for me... just giving me the starting line so then i can put it the effort to finish ok database looks good...thats what i was thinking.. didnt know if it would be too simple lol how would i grab the friends username?? my current like is website/memebers/username like so RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/.]+)/?$ members/index.php?page=profile&username=$1 Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536990 Share on other sites More sharing options...
DarkWater Posted May 9, 2008 Share Posted May 9, 2008 I also have an "accepted" column, and check if they're accepted or not (1 = accepted, 0 = not accepted). Switch it in the query. >_> I copied the wrong one. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537010 Share on other sites More sharing options...
runnerjp Posted May 9, 2008 Author Share Posted May 9, 2008 ahh yer,,, but still i dont understand where im oulling the firends id form and how? Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537022 Share on other sites More sharing options...
DarkWater Posted May 9, 2008 Share Posted May 9, 2008 The friend's username? It pulls it in the query. It only pulls the friends info on the query. while ($row = mysql_fetch_assoc($result)) { echo $row['username'] . "<br />"; } That'll output the usernames of all the friends of the person. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537028 Share on other sites More sharing options...
runnerjp Posted May 9, 2008 Author Share Posted May 9, 2008 yes but i mean when adding them Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537074 Share on other sites More sharing options...
DarkWater Posted May 9, 2008 Share Posted May 9, 2008 Pass it in the URL. Then make sure it's not already in the database with that user. Set accepted = 0 until the user accepts it. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537077 Share on other sites More sharing options...
runnerjp Posted May 10, 2008 Author Share Posted May 10, 2008 humm ok so to get a users username...seems i use RewriteRule ^([^/.]+)/?$ members/index.php?page=profile&username=$1 i could get it byyyy <a href='friendrequest.php?user=$username'>Add as Friend</a> on the lines i think but its the $username im not so sure then the firend request page would beeeeee <?php session_start(); //starts session include "../settings.php"; //include config { if ($_GET[user]){ //gets username $username = htmlspecialchars($_GET[user]); //friend $by = $_session[username]; //the person $query = mysql_query("INSERT INTO `friend_requests` ( `username` , `by` ) VALUES ( '$username' , '$by' )"); //inserts the request echo ( "$username has been sent a request you must now wait for it to be accepted" ); //echos completion } else { echo ( "No request was made" ); // or no request sent } } ?> this will work just grabbing the username of the friend Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537493 Share on other sites More sharing options...
runnerjp Posted May 10, 2008 Author Share Posted May 10, 2008 ahh ok im getting Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/runningp/public_html/members/friendrequest.php on line 8 PHP <?php session_start(); //starts session include "../settings.php"; //include config { if ($_GET['user']){ //gets username $username = htmlspecialchars($_GET['user']); //friend $by = $_session['username']; //the person $query = mysql_query("INSERT INTO `friend_requests` ( `username` , `by` ) VALUES ( '$username' , '$by' )"); //inserts the request echo ("$username has been sent a request you must now wait for it to be accepted"); //echos completion } else { echo ("No request was made"); // or no request sent } } ?> now i cant see any whitespace or t_encapsed can u :S Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537564 Share on other sites More sharing options...
runnerjp Posted May 10, 2008 Author Share Posted May 10, 2008 ok lots of change... im now getting the error QUERY ERROR: INSERT INTO friend_requests (username,by) VALUES ('emma','1') You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by) VALUES ('emma','1')' at line 1 <?php session_start(); include "../settings.php"; if ( !empty($_GET['user']) ) { $username = htmlspecialchars($_GET['user']); $by = $_SESSION['user_id']; $query = "INSERT INTO friend_requests (username,by) VALUES ('$username','$by')"; $result= mysql_query($query) or die("QUERY ERROR:<br />{$query}<br />" . mysql_error() ); echo "$username has been sent a request you must now wait for it to be accepted"; // useful in troubleshooting the SQL statement echo "<p>{$query}</p>"; } else { echo "No request was made"; } ?> is this due to me using a id and a username Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537660 Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 (username, by) It wants a space I think. Between the , and by. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537666 Share on other sites More sharing options...
runnerjp Posted May 10, 2008 Author Share Posted May 10, 2008 ahhhh wait... by is allready used in sql...doh `by` will be the answer lol while im here im working on the second part,, starting to get to grips with functions and was wondering if i was to do this $add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , 'function get_username') "); how would i use the function proerly ?? new to this area Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537673 Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 Please stop using strings directly in your mysql query. Set it to a variable then use it. It makes your code MUCH neater. $query = "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '" . get_username() . "')"; $add = mysql_query($query) OR die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537675 Share on other sites More sharing options...
runnerjp Posted May 10, 2008 Author Share Posted May 10, 2008 ok i tried what you said and i got Warning: Missing argument 1 for get_username(), called in /home/runningp/public_html/members/friendrequest.php on line 13 and defined in /home/runningp/public_html/functions.php on line 309 function get_username ( $id ) { global $db; $query = "SELECT `Username` FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $id ); if ( $db->RecordCount ( $query ) == 1 ) { $row = $db->getRow ( $query ); return $row->Username; } else { return FALSE; } } Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537678 Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 So put the $id in...it's your function, I had NO idea what parameters it used. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.