elseif syntax?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tryfan
Forum Newbie
Posts: 3
Joined: Sat Aug 04, 2007 9:41 am

elseif syntax?

Post by Tryfan »

Could anyone tell me why i get an error after the elseif?

Parse error: syntax error, unexpected '{' in /var/www/html/test.php on line 16

Code: Select all

if (!isset ($_POST['title']))
	{
		echo '<p>You must enter a TITLE!</p>';
		}
		elseif (strlen($_POST['title'] > 60)
		{
		echo '<p>Your TITLE is too long, consider shortening it to less than 60 chars.</p>';
		}
		else
		{
		echo 'all is good';
	}
Driving me nuts as i can't see the problem.
celavi
Forum Newbie
Posts: 1
Joined: Sun Aug 05, 2007 11:24 am

Post by celavi »

Code: Select all

elseif (strlen($_POST['title'] > 60)  change to
elseif ( strlen($_POST['title'] > 60) )
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

My guess is celavi wanted to write:

Code: Select all

elseif (strlen($_POST['title'] > 60)  change to
elseif ( strlen($_POST['title']) > 60 )
PS: Another issue is that isset() can return true even on empty string. You should use !empty() instead of isset.
Last edited by VladSun on Sun Aug 05, 2007 12:49 pm, edited 2 times in total.
There are 10 types of people in this world, those who understand binary and those who don't
Tryfan
Forum Newbie
Posts: 3
Joined: Sat Aug 04, 2007 9:41 am

Post by Tryfan »

aah t he function strlen wasn't properly closed? I'm so blind!!

Thank you very much :D
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

VladSun wrote:You should use is_empty instead of isset.
the function is actually empty()
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Tryfan wrote:aah t he function strlen wasn't properly closed? I'm so blind!!
It's a very common error.
Post Reply