How should I skip what is already added?

I am trying to add all the things I have in one table and insert them into an old table. I discovered that some fields called email are already in my old table.

So, when I get all the ones from the old one and about to insert them, I would like to skip the ones that are already in the table.

The one I’m getting all the new ones from is called temp_tbl
I want them to fill at the end of members_tbl

The cell I want to check if it’s already there is called email

How should a check like that look to work for me? I have tried a couple of things, but I can’t make it work.
Luckily I made a backup of the table before trying…

The brute force approach would be to get a record from temp, and read members using the ‘key’ fields of the temp record. If you get a hit, decide whether you want to update that members record or not. If you don’t get a hit, then insert the temp data into members and repeat. Can’t think of anything more elegant, and wouldn’t waste the time trying if I were you.

So would this be the right way?


$query = "SELECT * FROM temp_tbl"; 	
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$email = $row['email'];
$sql    = "SELECT * FROM members_tbl WHERE email = '$email'";
$result = mysql_query($sql,$conn);
if(count($row) == 0)
{
//No row was found
$sql2 = "INSERT INTO members_tbl ('field1','field2') values('value1','value2')";
$result2 = mysql_query($sql2,$conn);
} else {
//The e-mail was found. Do nothing and continue with the next.
}

Is that the way it should be done?