Hi there weed and thanks very much for the help.
First off, I've changed the script to use mysqli. Thank you very much for the link and warning.
Secondly, I have a question about the code you've posted. If I needed to insert 'bob' into username, '61 into user_id and NOW() into bantime in the banlist entry for every found IP as well, how would I write that?
$query_ban="INSERT INTO banlist (user_id, username, bantime, ip) VALUES ('$user_id', '$username', 'NOW()', (SELECT DISTINCT ip FROM tracking WHERE user_id='$selected_id')";
Something like this, perhaps?