Page 1 of 1

elseif syntax?

Posted: Sun Aug 05, 2007 10:57 am
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.

Posted: Sun Aug 05, 2007 11:28 am
by celavi

Code: Select all

elseif (strlen($_POST['title'] > 60)  change to
elseif ( strlen($_POST['title'] > 60) )

Posted: Sun Aug 05, 2007 11:54 am
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.

Posted: Sun Aug 05, 2007 11:56 am
by Tryfan
aah t he function strlen wasn't properly closed? I'm so blind!!

Thank you very much :D

Posted: Sun Aug 05, 2007 12:12 pm
by John Cartwright
VladSun wrote:You should use is_empty instead of isset.
the function is actually empty()

Posted: Sun Aug 05, 2007 12:37 pm
by superdezign
Tryfan wrote:aah t he function strlen wasn't properly closed? I'm so blind!!
It's a very common error.