Forum Moderators: coopster
I'm getting a parse error in the following page.
trivia.php
<? include('cookiecheck.php');?>
<? include($headervar.$skin.$extension);?><?php
$str = "Gentry Inc Graphics is run by Pantheros";
str_rot13($str);$ans='answer';
if (isset($_POST['submit'])) { // if form has been submitted
if(!$ans && $ans == "") {
echo "Try answering the question, please.";
} elseif ($ans == "str_rot13($str);" {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "gentry inc graphics is run by pantheros") {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "pantheros") {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "Pantheros") {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "the webmistress") {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} else {
echo "I'm sorry, your answer is incorrect. :( Please do try again, another trivia question should be up very soon!<p>Thanks for trying!";
}
}
?><?php
} else {// if form hasn't been submitted
?>
<p class=title>Trivia question!</p>
<p>
If you can answer this question correctly, you'll be told the prize you'll receive once you give the correct answer. If not, theni'm sorry, you'll have to try again at another time.<p>
<b>Question is::</b><p>
Who is this site run by?<p>
The answer can be found in the string below.<p>
<? echo "$str";?>
<p>
Your answer is::</br>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<input type="text" name="answer" maxlength="150" size="17">
<?php
}
?><? include($footervar.$skin.$extension);?>
Any idea what my problem might be? I'm not very good at troubleshooting PHP yet. : / Much less writing the stuff. Heheh.
} elseif ($ans == "str_rot13($str);" { See how the parentheses don't match up on your elseif? The quotes and semicolin aren't helping either.
Try:
} elseif ($ans == str_rot13($str)[red][b])[/b][/red] { After you fix that, the next error you're likely to get is the one that dkin pointed out. You closed the first if condition too many times. Try deleting the } that dkin suggested or the next one up.
I wish you well,
Okay, i changed the script, which now looks like the following, but now i'm getting "Parse error: parse error, unexpected '{', expecting '(' in /trivia.php on line 25".
<? include('cookiecheck.php');?>
<? include($headervar.$skin.$extension);?><?php
$str = "Gentry Inc Graphics is run by Pantheros";
str_rot13($str);$ans='answer';
if (isset($_POST['submit'])) { // if form has been submitted
if(!$ans && $ans == "") {
echo "Try answering the question, please.";
} elseif ($ans == str_rot13($str)) {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "gentry inc graphics is run by pantheros") {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "pantheros") {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "Pantheros") {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "the webmistress") {
"Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif {
echo "I'm sorry, your answer is incorrect. :( Please do try again, another trivia question should be up very soon!<p>Thanks for trying!";
}
?><?php
else {// if form hasn't been submitted
?>
<p class=title>Trivia question!</p>
<p>
If you can answer this question correctly, you'll be told the prize you'll receive once you give the correct answer. If not, then i'm sorry, you'll have to try again at another time.<p>
<b>Question is::</b><p>
Who is this site run by?<p>
The answer can be found in the string below.<p>
<?php echo "$str";?>
<p>
Your answer is::</br>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<input type="text" name="answer" maxlength=150 size=17><? include($footervar.$skin.$extension);?>
your first if statement is never closed (no }).
your final elseif in the second if statement doesn't have a conditional statement ie the bit between the ().
you can do a else statement in an if statement where you are using else ifs.
so, for example:
if (something) {
// statements
} else if (something_else) {
// more statements
} else {
// catchall statements
}
<? include('cookiecheck.php');?>
<? include($headervar.$skin.$extension);?><?php
$str = "Gentry Inc Graphics is run by Pantheros";
$ans='answer';
if (isset($_POST['submit'])) { // if form has been submitted
$answered = 1;
if(!$ans && $ans == "") {
echo "Try answering the question, please.";}
elseif ($ans == "gentry inc graphics is run by pantheros") {
echo "Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "pantheros") {
echo "Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "Pantheros") {
echo "Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "the webmistress") {
echo "Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} else {
echo "I'm sorry, your answer is incorrect. :( Please do try again, another trivia question should be up very soon!<p>Thanks for trying!";
}
?><?php
} else {
?>
<p class=title>Trivia question!</p>
<p>If you can answer this question correctly, you'll be told the prize you'll receive once you give the correct answer. If not, then i'm sorry, you'll have to try again at another time.<p>
<b>Question is::</b>
<p>Who is this site run by:<p>
<p>Your answer is::</br>
<form method="post" action="echo "<? echo $_SERVER['PHP_SELF']?>"><input type="text" name="answer" size="17"><? include($footervar.$skin.$extension);?>
NOW what's wrong with it? -.-;
Post just the next 10 lines, and well see what we've got--or find the $ sign on line 44, and trace backwards, looking closely for a missing piece of punctuation.
echo "header include file is: ".$headervar.$skin.$extension."<br>\n";
echo "footer include file is: ".$footervar.$skin.$extension."<br>\n";
...then take a look in whatever the footer include file is. That's where the else condition probably should closed. Also where the form's sumbit button should be, and probably some hidden form fields...
Besides, if I were you, I'd want to know what's in all of the include files. Who knows what sort of mischief they're up to--like connecting to url.com?
Those other files are my skinning files. Basically, it's the header and footer HTML of the page, but it only has to load once, making the site load faster for me. It remembers which layout the visitor was using last. It also makes layout changing muuuuch easier on me. Cookiecheck.php grabs the cookie from the user for the layout and starts the session for the login script on the site. $headervar.$skin.$extension grabs the header file for the chosen header, and $footervar.$skin.$extension gets the footer info. They're not doing anything bad really.
The echo thing took away the layout information and simply told me which layout i have currently (though it doesn't show).
But why does the elseif (blah == blah) { echo "blahblah" } try to go to url.com/echo?
<?
include('cookiecheck.php');
include($headervar.$skin.$extension);
?><?php
$str = "Gentry Inc Graphics is run by Pantheros";
$ans='answer';
if (isset($_POST['submit'])) { // if form has been submitted
return;
if(!$ans && $ans == "") {
echo "Try answering the question, please.";}
elseif ($ans == "gentry inc graphics is run by pantheros") {
echo "Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "pantheros") {
echo "Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "Pantheros") {
echo "Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} elseif ($ans == "the webmistress") {
echo "Woohoo! You got it right. Now go sMail pantheros the answer you entered to get your Rainbow Star Rod!";
} else {
echo "I'm sorry, your answer is incorrect. :( Please do try again, another trivia question should be up very soon!<p>Thanks for trying!";
}
?><?php
} else { }
?>
<p class=title>Trivia question!</p>
<p>If you can answer this question correctly, you'll be told the prize you'll receive once you give the correct answer. If not, then i'm sorry, you'll have to try again at another time.<p>
<b>Question is::</b>
<p>Who is this site run by:<p>
<p>Your answer is::</br>
<form method="post" action="echo "<? echo $_SERVER['PHP_SELF']?>"><input type="text" name="answer" size="17">
<input type="submit" name="submit" value="Submit">
</form><? include($footervar.$skin.$extension);?>
It still wants to go to url.com/echo though.
[edit]Found that problem. Now it just shows a blank page when i enter an answer.[/edit]
return; line. When you enter the if condition, that's killing the whole script. Then do some echos, etc. to find your other errors. For example, try temporarily putting an echo "\$ans = $ans<br>\n"; line before and after the
$ans='answer'; line. Also, do you understand that the name you use in a form field determines the $variable name retrieved by a script?
I wish you well.