# Redirect user after email is found in SQL DB

**URL:** <https://forum.kirupa.com/t/redirect-user-after-email-is-found-in-sql-db/195616>\
**Category:** Uncategorized\
**Created:** [August 1, 2006, 10:42pm UTC](https://forum.kirupa.com/t/redirect-user-after-email-is-found-in-sql-db/195616 "2006-08-01T22:42:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hey\_suburbia](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@hey\_suburbia](https://forum.kirupa.com/u/hey_suburbia)\
**Post date:** [August 1, 2006, 10:42pm UTC](https://forum.kirupa.com/t/redirect-user-after-email-is-found-in-sql-db/195616/1 "2006-08-01T22:42:45Z")

</div>

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:

```auto
<?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:

```auto
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
