Set the page up if this action happens

I’m making a registration form and I want to set a web page up a certain way depending on the action (i.e User name in use, E-mail in use, registration successful). Does anyone have any tips on how to do that. I know the header function won’t work because it’s not the first thing on the page.


<?php
require("includes/connect.php");
require("includes/redirect.php");

$resultUser = mysql_query("SELECT COUNT(*) FROM `sq_users` WHERE `Username`= "$_POST[user]"");
if ($resultUser == 1) header("Location:http://localhost/social/eregister.php");

$resultEmail = mysql_query("SELECT COUNT(*) FROM `sq_users` WHERE `Email`= "$_POST[email]"");
if ($_POST['email'] == $resultEmail) header("Location:http://localhost/social/eregister.php");

$passwd = $_POST[password1];
$passenc = md5($passwd);

$verifyBase = microtime();
$verify = md5($verifyBase);

$sql = "INSERT INTO `sq_users` (`Username`, `Passwd`, `Email`, `Valid`)
VALUES 
('$_POST[user]', '$passenc', '$_POST[email]', '$verify')";

if(!mysql_query($sql,$con))
	{
		die('Error:' . mysql_error());
	}

mysql_close($con);
?>

For an example of what I’m talking about, go to Facebook and log in. Don’t use your correct password. You’ll see that it takes you to “login.php” with a parameter “?login_attempt=1”. When you take the parameter away, the page shows up differently. I want something like that, but I don’t know how to do the parameters. Thanks for the help (PS: I’m a beginner at PHP).

Where you currently have code like

header("Location:http://localhost/social/eregister.php");

Just add a parameter indicating the error

header("Location:http://localhost/social/eregister.php?user_exists=1");

Then in eregister.php, check $_GET to see what error to print if any

if (isset($_GET['user_exists'])) {
  echo "That username is already in use.";
} 

And your header function may still work, its only when you output things to the page first, you can have as many lines of code before your header as you like as long as they dont output anything.

I would be redirecting it to the document it’s already in, but I’d have a different parameter. Would I put the “isset” code in the PHP section of code or in the body of an HTML document?

Thanks for the help! It worked!