Page 1 of 1

Is there anything glaringly obviously wrong here?

Posted: Fri Apr 27, 2007 11:20 am
by Smasher
For whatever reason, if I uncomment this code I get a blank page for the entire file, even though error reporting is turned on to full.

Code: Select all

case 'registering' : 
	
try {
		if($_POST['email'] != $_POST['email2'])
			{throw new customException('Email 1 did not match email 2.');}

		if($_POST['password'] != $_POST['password2'])
			{throw new customException('Password 1 did not match Password 2.');}

		if($_POST['username'] == '')
			{throw new customException('You did not enter a username.');}

		if(!eregi("^([a-z0-9]+)([._-]([a-z0-9]+))*[@]([a-z0-9]+)([._-]([a-z0-9]+))*[.]([a-z0-9]){2}([a-z0-9])?$", $_POST['email'])) 
			{throw new customException('myemail@mydomian.com is an example of a working email address.');} 
}

	$userId = User::Register($_POST['username'], $_POST['password'], $_POST['email']);
	mail($_POST['email'], 'You have now registered', 'Welcome '.$_POST['username'].', your userid is '.$userId->id, "From: ". $admin_email);
	$smarty->assign('page_title', $titlebegin.' Registered');
	$smarty->assign('message','You have successfully registered, you may now access the private area.');
	$smarty->assign('page_include','success.tpl');
	$smarty->display('index.tpl');

catch (customException $e)
		{$smarty->assign($_POST);
		$smarty->assign('page_title', $titlebegin.' Register');
		$smarty->assign('page_include', 'register.tpl');
		$smarty->display('index.tpl');}

break;
I'm new to the exception handling stuff, so I'm abit clueless.

Posted: Fri Apr 27, 2007 11:37 am
by guitarlvr
if you are using apache, is there an error in your error.log file?

Wayne

Posted: Fri Apr 27, 2007 11:49 am
by Smasher
Nope, as its a server.

Posted: Fri Apr 27, 2007 12:05 pm
by Chris Corbyn
Your try/catch is not valid. catch must immediately follow try {}.

Code: Select all

try {
  //all code here
} //no code at all here
catch(Exception $e) {
  //catch logic here
}

Posted: Fri Apr 27, 2007 12:41 pm
by volka
Smasher wrote:Nope, as its a server.
Meaning your server does not use apache? Or your webserver does not have a logfile?

Posted: Fri Apr 27, 2007 6:20 pm
by Smasher
d11wtq wrote:Your try/catch is not valid. catch must immediately follow try {}.

Code: Select all

try {
  //all code here
} //no code at all here
catch(Exception $e) {
  //catch logic here
}
Well I didn't want this block of code to execute, below, unless theres no errors in the try.

Code: Select all

$userId = User::Register($_POST['username'], $_POST['password'], $_POST['email']);
        mail($_POST['email'], 'You have now registered', 'Welcome '.$_POST['username'].', your userid is '.$userId->id, "From: ". $admin_email);
        $smarty->assign('page_title', $titlebegin.' Registered');
        $smarty->assign('message','You have successfully registered, you may now access the private area.');
        $smarty->assign('page_include','success.tpl');
        $smarty->display('index.tpl');

Posted: Sun Apr 29, 2007 3:42 pm
by Smasher
bump.

Posted: Sun Apr 29, 2007 3:53 pm
by John Cartwright
Once an exception is thrown, any other code within the try{ } is skipped.

Code: Select all

try 
{
	throw new Exception('Bleh');
	echo 'Tried';
}
catch (Exception $e)
{
	echo 'Caught';
}
Will only output "Caught"