|
Posted by Christoph Burschka on 11/16/06 07:03
Christoph Burschka wrote:
> linda wrote:
>> Sigh thought I'd found it, but no, also noticed I had a closing
>> bracket after the included header, but that did nothing the hunt still
>> goes on... this is driving me mad!
>>
>> "linda" <n0spamF0rme@tiscali.co.uk> wrote in message
>> news:455b839d$1_3@mk-nntp-2.news.uk.tiscali.com...
>>> Can anyone see the error! I've been looking for over three hours and
>>> I just can find it. I'm getting a parse error. I just can't find
>>> it, what am I missing? Sigh.... I hoping someone else can see it.
>>>
>>> Best wishes,
>>> Linda
>>>
>>> <?php
>>> $title = 'Register';
>>> include_once 'includes/header.html';
>>> ?>
>>> //Check if the form has been submitted.
>>> if (isset($_POST[submitted])) {
>>>
>>> $errors = array(); //Initialize error array.
>>>
>>> //Check for a name.
>>> if (empty($_POST['name'])) {
>>> $errors[] = 'You forgot to enter your name.';
>>> }
>>>
>>> //Check for an email address.
>>> if (empty($_POST['email'])) {
>>> $errors[] = 'You forgot to enter your email address.';
>>> }
>>>
>>> //Check for a password and match against the confirmed password.
>>> if (empty($_POST['password1'])) {
>>> if ($_POST['password1'] !=$_POST['password2']) {
>>> $errors[] = 'Your passwords did not match.';
>>> }
>>> } else{
>>> $errors[] = 'You forgot to enter your password.';
>>> }
>>>
>>> //Register the user here.
>>>
>>>
>>>
>>>
>>> //Send them an email.
>>> $body = "Thank you for registering with us.\n\nYour Password Is:
>>> '{$_POST['password1']}'.\n\nSincerely Admin\nMy domain name";
>>> mail ($_POST['email']), 'Thank you for registering', $body, 'From:
>>> admin@mydomain.co.uk';
>>>
>>> echo '<h2>Thank You!</h2>
>>> <p>You are now registered. An email has been sent to your email
>>> address confirming the information.<br />';
>>>
>>> //Report the errors.
>>> }else{
>>>
>>> echo '<h2>Error!</h2>\n
>>> <p>The following error(s) occured:<br /></p>';
>>>
>>> foreach ($errors as $msg) { //Print each error message.
>>> echo " - $msg<br />\n";
>>> }
>>> echo '</p><p>Please correct the fields.<br /></p>';
>>> } else{
>>> //Display the form.
>>> ?>
>>>
>>> <fieldset>
>>> <legend><h2>Register For An Account</h2></legend>
>>> <form action="register.php" method="POST">
>>> <input type="hidden" value="TRUE" name="submitted" />
>>> <p align="left">Please ensure the email you supply is valid, as
>>> accounts where email confirmations bounced back after registration
>>> <b>are deleted</b>!</p>
>>> <table>
>>> <tr>
>>> <td>Name: </td>
>>> <td><input type="text" name="name" size="50" /></td>
>>> </tr>
>>> <tr>
>>> <td>Email Address: </td>
>>> <td><input type="text" name="email" size="50" /></td>
>>> </tr>
>>> <tr>
>>> <td>Password: </td>
>>> <td><input type="password" name="password1" /></td>
>>> </tr>
>>> <tr>
>>> <td>Confirm Password: </td>
>>> <td><input type="password" name="password2" /></td>
>>> </tr>
>>> <tr>
>>> <td COLSPAN="2" align="right"><input type="submit" value="Register"
>>> /></td>
>>> </tr>
>>> </table>
>>> </form>
>>> </fieldset>
>>>
>>>
>>> <?php
>>> }//Close the main IF_ELSE.
>>> include_once 'includes/footer.html';
>>> ?>
>>>
>>
>>
>
> There are several issues here. Not all of them cause parsing errors, but
> they will make the script work other than probably intended.
>
> 1. mail ($_POST['email']), 'Thank you for registering', $body, 'From:
> admin@mydomain.co.uk';
>
> The closing paranthesis needs to be moved.
>
> 2. The if-else tree is quite tricky to see through. This is probably why
> you hadn't noticed the double else around line 53. There are some other
> problems (take a close look at the password validation; the way it's
> now, the form will always claim you didn't enter a password), but this
> is the only one that causes a parsing error.
>
> 3. You are adding to an array of error messages, and you have code in
> place that will echo them, but you never check if errors occurred: The
> user will be registered and the mail sent regardless of errors.
>
> I had some time just now to fix the script up a bit (along with a few
> minor things like code indentation and validating the email address). It
> worked and sent an email when I tested it.
>
> I'm not familiar with newsgroups so I don't know if I can send
> attachments here. If not, I'll paste it into the next message.
>
In case that didn't work, here it is again, pasted:
<?php
$title = 'Register';
include_once('includes/header.html');
//Check if the form has been submitted.
if (isset($_POST['submitted'])) {
$errors = array(); //Initialize error array.
//Check for a name.
if (empty($_POST['name'])) {
$errors[] = 'You forgot to enter your name.';
}
//Check for an email address.
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
if (!preg_match('/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9\-\._]+/',$_POST['email'])) {
// won't catch all errors, but the most blatant ones.
$errors[] = '"'.$_POST['email'].'" is not a valid email address.';
}
}
//Check for a password and match against the confirmed password.
if (empty($_POST['password1'])) {
$errors[] = 'You forgot to enter your password.';
}
else if ($_POST['password1'] !=$_POST['password2']) {
$errors[] = 'Your passwords did not match.';
}
if (!$errors) {
//Register the user here.
//Send them an email.
$body = "Thank you for registering with us.\n\nYour Password Is:
'{$_POST['password1']}'.\n\nSincerely Admin\nMy domain name";
mail ($_POST['email'], 'Thank you for registering', $body, 'From:
admin@mydomain.co.uk');
echo '<h2>Thank You!</h2>
<p>You are now registered. An email has been sent to your email address
confirming the information.<br />';
}
else {//Report the errors.
echo '<h2>Error!</h2>\n
<p>The following error(s) occured:<br /></p>';
foreach ($errors as $msg) { //Print each error message.
echo " - $msg<br />\n";
}
echo '</p><p>Please correct the fields.<br /></p>';
}
}
if (!isset($_POST['submitted']) || $errors) { //Either errors occurred, or it's not submitted yet.
//Display the form.
?>
<fieldset>
<legend><h2>Register For An Account</h2></legend>
<form action="" method="POST">
<input type="hidden" value="TRUE" name="submitted" />
<p align="left">Please ensure the email you supply is valid, as accounts
where email confirmations bounced back after registration <b>are
deleted</b>!</p>
<table>
<tr>
<td>Name: </td>
<td><input type="text" name="name" size="50" value="<?=$_POST['name']?>" /></td>
</tr>
<tr>
<td>Email Address: </td>
<td><input type="text" name="email" size="50" value="<?=$_POST['email']?>" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password1" /></td>
</tr>
<tr>
<td>Confirm Password: </td>
<td><input type="password" name="password2" /></td>
</tr>
<tr>
<td COLSPAN="2" align="right"><input type="submit" value="Register" /></td>
</tr>
</table>
</form>
</fieldset>
<?php
}
include_once('includes/footer.html');
?>
--
CB
Navigation:
[Reply to this message]
|