Jump to content


Photo

Parse Error with FOREACH()


  • Please log in to reply
2 replies to this topic

#1 CMellor

CMellor
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationLeeds, UK

Posted 18 August 2006 - 05:04 PM

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:

<?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;
	?>

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

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


Line 86 been: foreach($error as $value) {

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 if(!$error) { echo("bleh"); } else { I just have if($error) { which I doubt should make a big difference right?

Any help given will be greatly appreciated.

Thank you for you're time.

Chris.

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 18 August 2006 - 05:13 PM

Its not the foreach line, But the line above that. You have a missing semi-colon - ; - at the end of line 87 which is this:
$msg .= "<ul>\n"
Add a semi-colon at the end of that line.

#3 CMellor

CMellor
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationLeeds, UK

Posted 18 August 2006 - 05:15 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users