suttercain Posted March 10, 2007 Share Posted March 10, 2007 Simple submit form and I am getting a parsing error: <?php extract ($_REQUEST); if (! isset ($submit_age) or $age =="") { print "You Must Submit Your Age...<br />"; exit; } if ($age < 21) { print "Sorry, youre too young to drink!"; } else ($age >= 21) print "Cool, youre $age! Lets get fu__ed up!!!"; } ?> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/ Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 <?php extract ($_REQUEST); if (!isset($submit_age) || $age =="") { print "You Must Submit Your Age...<br />"; exit; } if ($age < 21) { print "Sorry, youre too young to drink!"; } else ($age >= 21) print "Cool, youre $age! Lets get fu__ed up!!!"; } ?> or = || --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204439 Share on other sites More sharing options...
suttercain Posted March 10, 2007 Author Share Posted March 10, 2007 Thanks frost, but I fixed that and it says error on line 20. Which is print "Cool, youre $age! Lets get fu__ed up!!!"; Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204442 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 else ($age >= 21) { print "Cool, youre $age! Lets get fu__ed up!!!"; } Need curly brackets at both ends. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204444 Share on other sites More sharing options...
Barand Posted March 10, 2007 Share Posted March 10, 2007 FrosT, regarding or / || read http://www.php.net/manual/en/language.operators.logical.php Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204445 Share on other sites More sharing options...
suttercain Posted March 10, 2007 Author Share Posted March 10, 2007 Did it, I saw that one, but now it says line 19.... All mixed up and I don't know what to do. Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204446 Share on other sites More sharing options...
suttercain Posted March 10, 2007 Author Share Posted March 10, 2007 Barand... so or is okay ansd so is and... right? Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204447 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 Did you do this? <?php extract ($_REQUEST); if (!isset($submit_age) || $age =="") { print "You Must Submit Your Age...<br />"; exit; } if ($age < 21) { print "Sorry, youre too young to drink!"; } else ($age >= 21) { print "Cool, youre $age! Lets get fu__ed up!!!"; } ?> Add the bracket on the else? If so than please post the error that it gives you. My bad barand, I forgot that php allows both. Thanks for correcting me. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204449 Share on other sites More sharing options...
suttercain Posted March 10, 2007 Author Share Posted March 10, 2007 Here is the current code: <?php extract ($_REQUEST); if (! isset ($submit_age) or $age =="") { print "You Must Submit Your Age...<br />"; exit; } if ($age < 21) { print "Sorry, youre too young to drink!"; } else ($age >= 21) { print "Cool, youre $age! Lets get fu__ed up!!!"; } ?> Here is the error message: Parse error: parse error, unexpected '{' in D:\wamp\www\PHP Tutorials\By Example\examples\chapter7_examples\lab_1a.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204450 Share on other sites More sharing options...
Barand Posted March 10, 2007 Share Posted March 10, 2007 Both work, but as it says in the manual, precedence is slightly different. Whenever I use || I always put the conditions in parentheses to avoid precendence problems, paticularly when mixing && and || EG if (!isset($submit_age) || ($age =="") ) Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204451 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 <?php extract ($_REQUEST); if (! isset ($submit_age) or $age =="") { print "You Must Submit Your Age...<br />"; exit; } if ($age < 21) { print "Sorry, youre too young to drink!"; } else { print "Cool, youre $age! Lets get fu__ed up!!!"; } ?> OR <?php extract ($_REQUEST); if (! isset ($submit_age) or $age =="") { print "You Must Submit Your Age...<br />"; exit; } if ($age < 21) { print "Sorry, youre too young to drink!"; } elseif ($age > 20 { print "Cool, youre $age! Lets get fu__ed up!!!"; } ?> The else either has to be an elseif for the condition or just an else without a condition to Barand, That is actually a really good idea. I am going to have to use it. Thanks for the insight (I have had problems with that in the past) --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204452 Share on other sites More sharing options...
suttercain Posted March 10, 2007 Author Share Posted March 10, 2007 BINGO... I can't believe I didn't catch that. None the less, thanks frost. elseif was the correction. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204453 Share on other sites More sharing options...
Barand Posted March 10, 2007 Share Posted March 10, 2007 @FrosT It's particularly problematic when you have something like this <?php if (a == b && c == d || c == e) ?> Do you really mean this (default without the ()s ) <?php if ( (a == b && c == d) || (c == e) ) ?> or do you mean this <?php if ( (a == b) && ( (c == d) || (c == e) ) ) ?> Quote Link to comment https://forums.phpfreaks.com/topic/42144-solved-why-am-i-getting-a-parsing-error/#findComment-204466 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.