Jump to content

[SOLVED] Why am I getting a parsing error?


suttercain

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

@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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.