Redirect user after email is found in SQL DB

I want to redirect a user to a “logged in” page after their email is found to exist in my database.

I’m using PHP and mySQL.

Here is what I have:

<?php


mysql_connect("localhost","user","pass"); 
	

mysql_select_db("db"); 

$email = $_POST['email'];
   
$fetch_exist=mysql_query("SELECT email FROM db WHERE email = '$email'");

if(mysql_num_rows($fetch_exist)>0)
{
		header('Location: www.site.com/page1.html'); 
		exit;
	}

else
{
	$error_message .="
	That Email is not in our database. 
 
	Please register here: www.site.com/page2.html
	";
	die ($error_message);
	}

?>

The connection works fine because I was able to get a text output on both, it’s the redirection script that causes errors:

header('Location: http://www.google.com'); 
		exit;

It says that the headers have been sent and normally I would know how to fix this (just put the “location” script at the very top of the page and that’s it.

Anyone know how I would do this?

What has to happen:

If email exists, user goes to page1.html.
If email doesn’t exist, user goes to page2.html