Jump to content

Parse Error with FOREACH()


CMellor

Recommended Posts

Hello,

I have found a new way to produce errors when submitting a form, ya know so if something isn't filled in, it will produce an error. Here is my code:

[code]<?php // error checking
if($_POST['submit']):

if(!$_POST['username']) $error[] = "A username was not entered"; // No username was entered
if(!$_POST['password'] || !$_POST['cpassword']) $error[] = "Please enter a password"; // No password was entered
if(strlen($_POST['password']) < 6 || strlen($_POST['cpassword']) < 6) $error[] = "Youre passwords do not match"; // Passwords less than 6 characters
if($_POST['password'] != $_POST['cpassword']) $error[] = "The passwords do not match"; // Passwords do not match
if(!$_POST['email'] || !$_POST['cemail']) $error[] = "An e-mail was not entered"; // No e-mail was entered
if(!checkmail($_POST['email']) || !checkmail($_POST['cemail'])) $error[] = "Youre e-mail address is an invalid format"; // E-Mail address is invalid
if($_POST['email'] != $_POST['cemail']) $error[] = "Youre e-mail address do not match"; // E-Mail address' do not match
if(!$_POST['roleplay']) $error[] = "You did not provide a sample role play"; // No role play entered

if($error) { // if an error is found
$msg = "<p>The following error\'s occured:<br />\n";
$msg .= "<ul>\n"
foreach($error as $value) {
$msg .= "<li>$value</li>\n";
}
$msg .= "</ul></p>\n";
}
endif;

echo $msg;
?>[/code]

Now when I try to run the code, I get this error:

[quote]Parse error: parse error in c:\server\www\join\application.php on line 86[/quote]

Line 86 been: [b]foreach($error as $value) {[/b]

What's odd is I have tried this on my localhost on a different page and that work's perfectly, but yet this code, which the only difference is that I have a few more $error[] variables and instead of [i]if(!$error) { echo("bleh"); } else {[/i] I just have [i]if($error) {[/i] which I doubt should make a big difference right?

Any help given will be greatly appreciated.

Thank you for you're time.

Chris.
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.