Jump to content

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


disoriented guy

Recommended Posts

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:

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

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

[code]<?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;
}

?>[/code]

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

Thanks
Link to comment
Share on other sites

try this:
[code]
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';
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.