runnerjp Posted May 10, 2008 Author Share Posted May 10, 2008 wopps i didnt enter id lol... ok i get this im getting Parse error: syntax error, unexpected T_VARIABLE in /home/runningp/public_html/members/friendrequest.php on line 13 so 13 = $query = "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '" . get_username() . "')" and my whole code looks like so <?php session_start(); include "../settings.php"; if ( !empty($_GET['user']) ) { if ( ctype_alnum($_GET['user']) && strlen($_GET['user']) <= 10 ) { // further test and escape data } $username =($_GET['user']); $id = $_SESSION['user_id'] $query = "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '" . get_username() . "')"; $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 } else { echo "No request was made"; } ?> Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-537685 Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 You need to enclose arrays in {}. so 13 = $query = "INSERT INTO `friends` (`friendname` , `username`) VALUES ('{$_GET['user']}' , '" . get_username() . "')" Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-537686 Share on other sites More sharing options...
runnerjp Posted May 10, 2008 Author Share Posted May 10, 2008 humm u see i tried that when waiting for a reply but it still shows the same error Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-537688 Share on other sites More sharing options...
runnerjp Posted May 10, 2008 Author Share Posted May 10, 2008 ok new part now ... i got <?php session_start(); // starts sessions include "../settings.php"; // inlcudes config switch ($_GET[friends]) { //allows multiple pages default: $id = $_SESSION['user_id']; $get_username_value = get_username($id); $get = mysql_query( "SELECT * FROM `friend_requests` WHERE `username` = '$get_username_value' "); $result= mysql_query($get) or die("QUERY ERROR:<br />{$query}<br />" . mysql_error() ); //gets requests while ($reqs = mysql_fetch_array($get)) { echo ( "Friend Requests $reqs[by_user] wants to be friends with you. <a href='newfriends.php?friends=accept&user=$reqs[by_user]'>Accept</a><br/> <a href='newfriends.php?friends=delete&user=$reqs[by_user]'>Delete</a>" ); //displays requests and shows accept delete links } break; case 'accept': //accept page if ($_GET[user]) { //get username $get_username_value = get_username($id); $add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '$get_username_value') "); // add to your friends list $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by_user` = '$_GET[user]' "); // deletes friend request echo ( "$_GET[user] has been added as a friend and the request has been deleted" ); // echos the completion } break; //ends accept page case 'delete': // delete page if ($_GET[user]) { //gets username $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by_user` = '$_GET[user]' "); // deletes friend request echo ( "$_GET[user]'s request has been deleted" ); // echos completion } break; //ends delete page } // ends switch ?> but im getting QUERY ERROR: 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 'Resource id #8' at line 1 Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-537759 Share on other sites More sharing options...
runnerjp Posted May 11, 2008 Author Share Posted May 11, 2008 ok been playing around still lol and i seem to have got confused again... ok so in my table i currenty have ________________________ | username | by_user | |------------------------- | | Emma | Bob | but im getting the error QUERY ERROR: SELECT * FROM `friend_requests` WHERE `by_user` = Bob Unknown column 'Bob' in 'where clause' but bob is right there lol... and surly if it cant find bob it should display the oage still <?php session_start(); // starts sessions include "../settings.php"; // inlcudes config switch ($_GET[friends]) { //allows multiple pages default: $id = $_SESSION['user_id']; $get_username_value = get_username($id); $get = "SELECT * FROM `friend_requests` WHERE `by_user` = $get_username_value "; $result= mysql_query($get) or die("QUERY ERROR:<br />{$get}<br />" . mysql_error() ); //gets requests while ($reqs = mysql_fetch_array($get)) { echo ( "Friend Requests $reqs[by_user] wants to be friends with you. <a href='newfriends.php?friends=accept&user=$reqs[by_user]'>Accept</a><br/> <a href='newfriends.php?friends=delete&user=$reqs[by_user]'>Delete</a>" ); //displays requests and shows accept delete links } break; case 'accept': //accept page if ($_GET[user]) { //get username $get_username_value = get_username($id); $add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '$get_username_value') "); // add to your friends list $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by_user` = '$_GET[user]' "); // deletes friend request echo ( "$_GET[user] has been added as a friend and the request has been deleted" ); // echos the completion } break; //ends accept page case 'delete': // delete page if ($_GET[user]) { //gets username $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by_user` = '$_GET[user]' "); // deletes friend request echo ( "$_GET[user]'s request has been deleted" ); // echos completion } break; //ends delete page } // ends switch ?> Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-538162 Share on other sites More sharing options...
runnerjp Posted May 11, 2008 Author Share Posted May 11, 2008 woops ok found it...'quotes' lol <?php session_start(); // starts sessions include "../settings.php"; // inlcudes config switch ($_GET[friends]) { //allows multiple pages default: $id = $_SESSION['user_id']; $get_username_value = get_username($id); $get = "SELECT * FROM `friend_requests` WHERE `by_user` = '$get_username_value'"; $result= mysql_query($get) or die("QUERY ERROR:<br />{$get}<br />" . mysql_error() ); //gets requests { echo ( "Friend Requests $reqs[username] wants to be friends with you. <a href='newfriends.php?friends=accept&user=$reqs[username]'>Accept</a><br/> <a href='newfriends.php?friends=delete&user=$reqs[namername]'>Delete</a>" ); //displays requests and shows accept delete links } break; case 'accept': //accept page if ($_GET[user]) { //get username $get_username_value = get_username($id); $add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '$get_username_value') "); // add to your friends list $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by_user` = '$_GET[user]' "); // deletes friend request echo ( "$_GET[user] has been added as a friend and the request has been deleted" ); // echos the completion } break; //ends accept page case 'delete': // delete page if ($_GET[user]) { //gets username $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by_user` = '$_GET[user]' "); // deletes friend request echo ( "$_GET[user]'s request has been deleted" ); // echos completion } break; //ends delete page } // ends switch ?> now i im stuck,,, need some advie lol. ok the code doents pull the username of the person that wants to be accepted as a friend i just get /members/newfriends.php?friends=accept&user=?? how would i pull the user name out so i can have Name wants to be friends with you. Accept or Delete and how would you go about making it so that a message is displayed when there is a user waiting to become a friend? sorry i forgot to think this part through Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-538255 Share on other sites More sharing options...
Fadion Posted May 11, 2008 Share Posted May 11, 2008 ahh yer,,, but still i dont understand where im oulling the firends id form and how? This topic is open ended. Why on earth u go on creating a "big" project when your coding knowledge may be limited only to an echo "hello world". Read some stuff first, increase your knowledge and then start making sites. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-538268 Share on other sites More sharing options...
runnerjp Posted May 11, 2008 Author Share Posted May 11, 2008 but surly im learning by getting this far lol... all im askin is for some guidence Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-538272 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 ok i have it working but i was thinking.... this is what i have...very basic but working <?php session_start(); // starts sessions include "../settings.php"; // inlcudes config $id = $_SESSION['user_id']; $get_username_value = get_username($id); switch ($_GET[friends]) { //allows multiple pages default: $query = "SELECT * FROM friend_requests WHERE `by_user` = '$get_username_value' LIMIT 1"; if ($result = mysql_query($query)){ if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $puser = $array['username']; $puser2 = $array['by_user']; }} ?> <?php echo ( "Friend Requests $puser wants to be friends with you. <a href='newfriends.php?friends=accept&user=$puser'>Accept</a><br/> <a href='newfriends.php?friends=delete&user=$puser'>Delete</a>" ); //displays requests and shows accept delete links break; case 'accept': //accept page if ($_GET[user]) { //get username $get_username_value = get_username($id); $add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '$get_username_value') "); // add to your friends list $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by_user` = '$get_username_value' "); // deletes friend request echo ( "$_GET[user] has been added as a friend and the request has been deleted" ); // echos the completion } break; //ends accept page case 'delete': // delete page if ($_GET[user]) { //gets username $delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by_user` = '$get_username_value'"); // deletes friend request echo ( "$get_username_value's request has been deleted" ); // echos completion } break; //ends delete page } // ends switch ?> but i need to make it go both ways,,, so if 1 become friends with 2 then 2 will also be friends with 1 but how !!! Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-538894 Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 When you do the SELECT to view friends, have it do, in the WHERE clause: WHERE f.userid = $uid OR f.friendid = $uid Assuming $uid is your user ID. Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-538911 Share on other sites More sharing options...
runnerjp Posted May 12, 2008 Author Share Posted May 12, 2008 ahhh so i wouldnt have to add the users in the db both ways... so like this <?php session_start(); // starts sessions include "../../settings.php"; // inlcudes config $id = $_SESSION['user_id']; $get_username_value = get_username($id); $getfriends = mysql_query( "SELECT * FROM `friends` WHERE `username` = '$get_username_value' OR friend ='$get_username_value'" ); while ($friends = mysql_fetch_array($getfriends)) { echo "$friends[friendname]"; } ?> Link to comment https://forums.phpfreaks.com/topic/104908-adding-friends/page/2/#findComment-538916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.