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. 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 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!!!"; 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 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 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. 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? 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 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 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 =="") ) 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 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. 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) ) ) ?> 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
Archived
This topic is now archived and is closed to further replies.