That's not going to work as expected. Specifically "update table2 set col2=\'$var\'" will set col2 in EVERY row in table2 to be whatever is in $var. Even more specifcally, it will set every row to be equal to the last "column" returned form table1. Quite arbitrary.
In addition to using 2 db connections, you need to qualify your second SQL statement with a where statement.
Assuming I understand what you are trying to accomplish