So I've been trying to create a simple friend system. When you register, you get randomized numbers and chars of 8 in length. I save this number in a column to the user. I have been trying to insert the currently sessioned user(PHP), $SessionUser
together with the friends' username, uidUsers
using an "INSERT SELECT WHERE" statement, but something goes wrong. Heres something I have tried:
$sql = mysqli_query($conn, "INSERT into friends (uid1, uid2)
values($sessionUser, (SELECT uidUsers FROM users WHERE idFriendCode = $idFriendCode)");
Inside the table, friends
, I have two columns, uid1
(the sessioned user/sender) and uid2
(the reciever, name of specified $idFriendCode
). I want to insert the $sessionUser
to the uid1 and whatever username (uidUsers
) that matches with the $idFriendCode
to the uid2
. This does not seem to work and I don't know why. I imagine the problem is that I can't use a PHP variable like this.
I know that I don't use prepared statements. I have tried to implement it, but I think it's much harder than just using a basic mysqli_query().