Is there anything glaringly obviously wrong here?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smasher
Forum Commoner
Posts: 38
Joined: Fri Apr 20, 2007 5:22 am

Is there anything glaringly obviously wrong here?

Post 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.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

if you are using apache, is there an error in your error.log file?

Wayne
Smasher
Forum Commoner
Posts: 38
Joined: Fri Apr 20, 2007 5:22 am

Post by Smasher »

Nope, as its a server.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Smasher wrote:Nope, as its a server.
Meaning your server does not use apache? Or your webserver does not have a logfile?
Smasher
Forum Commoner
Posts: 38
Joined: Fri Apr 20, 2007 5:22 am

Post 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');
Smasher
Forum Commoner
Posts: 38
Joined: Fri Apr 20, 2007 5:22 am

Post by Smasher »

bump.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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"
Post Reply