I have a problem with this sql code.
I have a table friends with three columns user1, user2, pending.
user1 and user2 are primary keys of datatype int.
The phpmyadmin returns this error:
MySQL said: #1064 - 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 'Declare var int; Set var = SELECT COUNT(*) FROM friends WHERE ((user1 = id1 A' at line 1
note - i did it via phphmyadmin so i have This is my code:
Declare var int;
Set var = SELECT COUNT(*) FROM friends WHERE ((user1 = id1 AND user2=id2) OR (user1 = id2 AND user2=id1));
IF var = 0
BEGIN
INSERT INTO friends
( user1, user2,pending)
VALUES (id1, id2,1);
Print 'Data now added.';
END
ELSE
BEGIN
Print 'Dah! already exists';
END