Jump to content


Photo

error fixed, but extra clarification needed... see reply 7


  • Please log in to reply
9 replies to this topic

#1 disoriented guy

disoriented guy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 August 2006 - 04:39 PM

Sorry to bother you all, but this one has me stumped...
I'm starting to set up a basic registration script (obviously half finished).  When i runthe following code, i get this error:

Parse error: parse error, unexpected T_CATCH in c:\program files\apache group\Apache\htdocs\newaccount.php on line 83

Line 83 is the line near the bottom that starts catch (Exception $e).  Could you explain to me where i've gone wrong?

<?php
 
$name=(string)$_POST['name'];
$mail=(string)$_POST['email1'];
$password=(string)$_POST['password1'];
$mailcheck=(string)$_POST['email2'];
$passcheck=(string)$_POST['password2'];

function valid_email($address)
{
   if(ereg('^[a-zA-Z0-9 \._\-]+@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+
             [a-zA-Z]+$', $address))
      return true;
   else
      return false;
}


function filled_out($form_vars)
{
   //test that each variable has a value
   foreach ($form_vars as $key => $value)
   {
      if (!isset($key) || ($value == ''))
         return false;
   }
   return true;
}

try
{
   if (!filled_out($_POST))
   {
      throw new Exception('You have not filled out all the required fields - please try again.');
   }

   if (!valid_email($mail))
   {
      throw new Exception('This email address ius not valid - it must be, as this is used to send an activation email.');
   }

   if ($password != $passcheck)
   {
      throw new Exception('The passwords you entered do not match.');
   }

   if (strlen($password)<8)
   {
      throw new Exception('Your password must be greater than seven characters.');
   }
   
   echo 'Your registration was successful';
}
catch (Exception $e)
{
   echo 'Problems with your attempted registration:<br/>';
   echo $e->getMessage();
   exit;
}

?>

I'm running php5.1.4 and there is a form that sources this code... and the variables do match up.

Thanks

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 09 August 2006 - 04:44 PM

can't see any line in bold and only 60 lines of code so not sure what line it is with the error..
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 Corona4456

Corona4456
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts
  • LocationEl Paso, TX

Posted 09 August 2006 - 04:45 PM

Well if this is an exact copy of the code.  You aren't closing the if statement:

if ($password != $passcheck)
   {
      throw new Exception('The passwords you entered do not match.');

What is the CoronaMatrix?

#4 disoriented guy

disoriented guy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 August 2006 - 04:46 PM

only 60 lines because the html is not included - ive modified the post to show you the line that has the error.... sorry 'bout that

#5 disoriented guy

disoriented guy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 August 2006 - 04:47 PM

ooooh

thanks for that - stupid mistake, but bound to happen... must have missed it when i checked through :)

#6 Corona4456

Corona4456
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts
  • LocationEl Paso, TX

Posted 09 August 2006 - 04:48 PM

Heh... no problem I do that kind of thing all the time... so when I look at other's code that's the first thing I look at to make sure that isn't the root of the problem.
What is the CoronaMatrix?

#7 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 09 August 2006 - 04:51 PM

your missing a '}' here -

   if ($password != $passcheck)
   {
      throw new Exception('The passwords you entered do not match.');



#8 disoriented guy

disoriented guy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 August 2006 - 01:18 PM

..... and also, just to clarify, i have another question to ask regarding this code.

At the moment, only one error message at a time can be displayed - how can I make it display all the needed error messages without stopping after the first?

#9 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 10 August 2006 - 02:12 PM

try this:
try
{
   $error='';
   if (!filled_out($_POST))
   {
      $error.='You have not filled out all the required fields - please try again.<br>';
   }

   if (!valid_email($mail))
   {
      $error.='This email address ius not valid - it must be, as this is used to send an activation email.<br>';
   }

   if ($password != $passcheck)
   {
      $error.='The passwords you entered do not match.<br>';
   }

   if (strlen($password)<8)
   {
      $error.='Your password must be greater than seven characters.<br>';
   }
   if($error)
   {
        throw new Exception($error);
    }
   echo 'Your registration was successful';
}


#10 disoriented guy

disoriented guy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 August 2006 - 05:14 PM

Thanks very much for that - worked beautifully :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users