I am having trouble getting my if/elses to do what they should. It's probably something dumb that I'm overlooking. Can anyone help?

if(isset($_POST['homePageReg_submit']))
	{
		$db = new connectDB();
		$db->username = "";
		$db->password = "";
		$db->hostName = "";
		$db->dbName = "";
		$db->connect();
		
		$rf_username = $_POST['homePageReg_username'];
		$rf_email = $_POST['homePageReg_email'];
		
		$rf_validateEmail = new validateEmail();
		$rf_validateEmail->email = $rf_email;
		
		//check_email_address returns false if the email address doesnt pass validation.
		if($rf_validateEmail->check_email_address())
			{
				$tempPw = setPw();
				$rf_register = new registerUser();
				$rf_register->username = $rf_username;
				$rf_register->password = $tempPw;
				$rf_register->email = $rf_email;
				
				//compareUsernames returns false if either the username of email is already in the database.
				if($rf_register->compareUsernames())
					{
						$rf_register->register();
						$activate = new activationEmail();
						$activate->username = $rf_username;
						$activate->email = $rf_email;
						$activate->sendPw();
					}				
				else
					{
						//username taken
						header("location:../../index.php5?regError=1");
					}
		
				$db->closeConnection();
			}
		else
			{
				//invalid Email
				header("location:../../index.php5?regError=2");
			}
				
				header("location:../../index.php5?regSuccess=1");
	}

The problem is that even when I enter invalid emails or duplicate usernames it still just returns to index.php5?regSuccess=1. It doesn't enter the data into the database or send the email though. So it works, it just doesnt send the user to the right page after the script runs.

a header() call does not end the script. Always place exit; after a header() call if you don't want anything else to execute after it.

// do some stuff
header('Location: blah.php');
// this stuff gets executed too
header('Location: blah2.php'); // user is now redirected to blah2.php
exit;
// this stuff doesn't get executed
header('Location: blah3.php'); // never gets here, the user already left the page
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.