add an auto numbering INT PK column to both table 1 and table 2, then do:
// connect to db here
$result = mysql_query('SELECT id, name FROM table1') or exit(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
mysql_query("UPDATE table2 SET id = '" . $row['id'] . "' WHERE name = '" . $row['name'] . "'") or exit(mysql_error());
echo 'UPDATE ' . $row['id'] . ' OK<br>';
}
after you have verified the relational intergretity of the two tables you can (and should) delete the "name" column from table2 (it is now redundant data).