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
Tryfan
Forum Newbie
Posts: 3 Joined: Sat Aug 04, 2007 9:41 am
Post
by Tryfan » Sun Aug 05, 2007 10:57 am
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 » Sun Aug 05, 2007 11:28 am
Code: Select all
elseif (strlen($_POST['title'] > 60) change to
elseif ( strlen($_POST['title'] > 60) )
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Sun Aug 05, 2007 11:54 am
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 » Sun Aug 05, 2007 11:56 am
aah t he function strlen wasn't properly closed? I'm so blind!!
Thank you very much
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Aug 05, 2007 12:12 pm
VladSun wrote: You should use is_empty instead of isset.
the function is actually empty()
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Sun Aug 05, 2007 12:37 pm
Tryfan wrote: aah t he function strlen wasn't properly closed? I'm so blind!!
It's a very common error.