Jump to content

Archived

This topic is now archived and is closed to further replies.

CMellor

Parse Error with FOREACH()

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.

Share this post


Link to post
Share on other sites
Its not the foreach line, But the line above that. You have a missing semi-colon - [b];[/b] - at the end of line 87 which is this:
[code]$msg .= "<ul>\n"[/code]
Add a semi-colon at the end of that line.

Share this post


Link to post
Share on other sites
Dammit, I knew it would be something really simple, something that I missed o_0 that's always the case!

Thanks for pointing it out!

Share this post


Link to post
Share on other sites

×

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.