First.. You're using mysql_fetch_array when you wanted mysql_fetch_assoc.. .. select user_id from whatever .. and then $row = mysql_fetch_array($res) .. youd have a $row[0].. mysql_fetch_assoc would allow $row['user_id'] Secondly.. You can use one query to select all the info.. select e107.user_id FROM db2.e107_user as e107 left join db1.clanmembers as clan on e107.user_loginname = clan.user_loginname You'll still want to mysql_select_db($db2) for your insert query Thirdly.. I'd change the insert query to: $user_id = mysql_real_escape_string($user_id); $query = "INSERT INTO e107_private_msg VALUES (NULL, '1', '$user_id', NOW(), '0', 'Clan War 2', 'Clan War Arranged', '0', '0', '', '+rr+', '0')"; mysql_query($query) or die('Query 3 failed. ' . mysql_error()); Where the entire query is surrounded by double quotes, so you dont have to back slash singles.. $user_id is escaped, so its safe.. using mysql's NOW() function instead of php's time().. On 8/3/07, Arena Servers <smithster@xxxxxxxxxxxxxxxxxxxx> wrote: > mysql_select_db($db_name2); > > $query = "SELECT user_id FROM `e107_user` WHERE `user_loginname` = '$user_loginname'"; > > $result = mysql_query($query) or die('Query 2 failed. ' . mysql_error()); > > while ($row = mysql_fetch_array($result)){ > > $user_id = ($row['user_id']); > > $query = 'INSERT INTO e107_private_msg VALUES (NULL, \'1\', \''.$user_id.'\', \''.$time.'\', \'0\', \'Clan War 2\', \'Clan War Arranged\', \'0\', \'0\', \'\', \'+rr+\', \'0\');'; > > $result = mysql_query($query) or die('Query 3 failed. ' . mysql_error()); > > } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php