5 Replies - 543 Views - Last Post: 01 November 2011 - 06:19 AM Rate Topic: -----

#1 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

else error message

Posted 31 October 2011 - 07:04 PM

Could someone help me understand this error message?

The code is:
$errors=array();
	if(isset($_POST['submit'])){
	validate_input();
  	else {
		display_form();	
	}
	}


the error message is Parse error: syntax error, unexpected T_ELSE in /home/content/a/u/n/auntievics/html/checkOut.php on line 38
Is This A Good Question/Topic? 0
  • +

Replies To: else error message

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10565
  • View blog
  • Posts: 39,104
  • Joined: 27-December 08

Re: else error message

Posted 31 October 2011 - 07:28 PM

Your else statement is contained in your if statement. Check your curly braces.
Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: else error message

Posted 31 October 2011 - 07:51 PM

Proper indentation makes stuff like this much easier to spot. I mean, if I re-arrange your code like this:
$errors=array();
if(isset($_POST['submit'])) {
	validate_input();
	else {
		display_form();	
	}
}


The error becomes fairly obvious.
Was This Post Helpful? 1
  • +
  • -

#4 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

Re: else error message

Posted 31 October 2011 - 08:27 PM

I'm not quite following you. It I checked and all the curly brackets are matched. I even tried deleting the curly brackets around the else statement, but that didn't help Either. Can you help me a little bit more?
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: else error message

Posted 31 October 2011 - 08:42 PM

All else blocks must follow an if block. The error in your code is that you put the else block inside the if block.

// How it should look:
if ( something ) {
    // Do something
}
else {
	// Do something else
}

// And this is how your's looks:
if ( something ) {
	// Do something
	else {
		// Do something else
	}
}


Was This Post Helpful? 1
  • +
  • -

#6 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

Re: else error message

Posted 01 November 2011 - 06:19 AM

that helped. Thank you so much
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1