Alright, i have a seperate table in my DB called: friends It has 3 rows 1. id ( incremented row id .. nothing special ) 2. user ( the user who added the other user as their friend ) 3. myfriend ( the friend of user that they added ) Right now in the add friend file, all i have for adding the friend ( works fine ) is: mysql_query("INSERT INTO friends (user, myfriend) VALUES('$uid', '$mem' ) ") or die(mysql_error()); echo "<b><center><font size='4'><u>$mem</u> is now your friend!</font></u></center></b><br>"; echo "<br><br><center><b><font size='5'><a href='member.php?msg=added'>Back to Member Area</a></font></b></center><br><meta http-equiv='refresh' content='3;url=http://www.**********/member.php?msg=added'>"; Code (markup): But i need it to check if user has already added myfriend , and if they have, don't add them again and echo a message saying " $mem is already your friend! " So, it checks if " user " has added " myfriend " before in the DB, and if they have, it wont show/do the insert into friends , and instead echo the message saying " $mem is already your friend! " error. $5 paypal to the first person who get's me a working code that i try and am happy with!
I'm not a MySQL expert, so my way may not be the best, but it should work. $result = mysql_query("SELECT FROM friends WHERE user='$uid' AND myfriend='$mem') if (!$result) echo "Query failed!" . mysql_error(); else if ($row = mysql_fetch_array($result)) { echo("$mem is already your friend"); } else { mysql_query("INSERT INTO friends (user, myfriend) VALUES('$uid', '$mem' ) ") or die(mysql_error()); echo "<b><center><font size='4'><u>$mem</u> is now your friend!</font></u></center></b><br>"; } Code (markup): I'll check and verify that this works, but go ahead and try it out. If it does, my paypal is
Im getting: Parse error: syntax error, unexpected T_STRING in /home/ffilehos/public_html/***/maddfriend.php on line 117 Which is: 116: if (!$result) 117: echo "Query failed!" . mysql_error(); 118: else
Just remove those 3 lines and see how it goes. They aren't awfully important, just a test to make sure that the query works first. Let me know how it works after that.
Parse error: syntax error, unexpected T_VARIABLE in /home/ffilehos/public_html/*****/maddfriend.php on line 118
117: if ($row = mysql_fetch_array($result)) { 118: echo("$mem is already your friend"); 119: } else {
Which lines ? Im using this below, removed the 3 lines you said: $result = mysql_query("SELECT FROM friends WHERE user='$uid' AND myfriend='$mem') if ($row = mysql_fetch_array($result)) { echo("$mem is already your friend"); } else { mysql_query("INSERT INTO friends (user, myfriend) VALUES('$uid', '$mem' ) ") or die(mysql_error()); echo "<b><center><font size='4'><u>$mem</u> is now your friend!</font></u></center></b><br>";
Wait, also need to add something else. $result = mysql_query("SELECT FROM friends WHERE user='$uid' AND myfriend='$mem'"); I forgot the double quote at the end.
Still: Parse error: syntax error, unexpected T_VARIABLE in /home/ffilehos/public_html/insanetext/maddfriend.php on line 118 w/o the 3 lines
Exactly: $result = mysql_query("SELECT * FROM friends WHERE user='$uid' AND myfriend='$mem'); if ($row = mysql_fetch_array($result)) { echo "$mem is already your friend"; } else { mysql_query("INSERT INTO friends (user, myfriend) VALUES('$uid', '$mem')") or die(mysql_error()); echo "<b><center><font size='4'><u>$mem</u> is now your friend!</font></u></center></b><br>"; } Code (markup):
There was something that I had missed earlier, that might be causing it. Try this first: $result = mysql_query("SELECT * FROM friends WHERE user='$uid' AND myfriend='$mem'"); Add the double quote to the end of the line just before the closing parenthesis.
I think its working! No error codes, and i added someone who is already my friend and it didnt do so, and showed the error let me test it for like two more minutes, i already have your paypal but ill let you know anyway!
Good deal. Sorry for missing that earlier, I guess I was just typing too quick so I could be the first to reply.
$query = "INSERT INTO friends(id, user, myfriend) VALUES('', '$uid', '$mem' ) "; if(!$query) { echo "error"; } else { echo "<b><center><font size='4'><u>$mem</u> is now your friend!</font></u></center></b><br>"; echo "<br><br><center><b><font size='5'><a href='member.php?msg=added'>Back to Member Area</a></font></b></center><br><meta http-equiv='refresh' content='3;url=http://www.**********/member.php?msg=added'>"; }