Jump to content

[SOLVED] My form breaks my includes


Marfisa

Recommended Posts

Sorry if this there is an obvious answer, but I'm having trouble with this.

 

I have some includes with full paths at the top of my page. Then I have this form-

 

<form action="games_snoop.php?answer" method="post">

<input type="text" name="character" size="20"><br>
<input type="submit" value="Guess!">
</form>

 

Later in the page, I am using this bit of code to display if the answer was correct-

 

<? } elseif ($_SERVER['QUERY_STRING'] == "answer") {

 

The problem is that when it gets to the URL with games_snoop.php?answer, all the includes can no longer be found. I get this error.

 

Warning: main(top.php) [function.main]: failed to open stream: No such file or directory in

 

It looks like it's just looking for the included files in the current directory, ignoring the full path I had specified.

 

This is the page with the problem if you want to see it in action.

The correct answer for the form is "osakanaru".

 

http://legend.neo-romance.net/games/snoop.php

 

The includes work on the main part of the page.

Link to comment
Share on other sites

<?php

include('/home/.lafayette/clavis/legend.neo-romance.net/top.php');
include('/home/.lafayette/clavis/legend.neo-romance.net/reward.php');

if(!$_SERVER['QUERY_STRING']) { ?>

<h1>snoop!</h1>

<P align="center">
<img src="images/snoop00.jpg">
</P>

<P>
Every time Usagi is about to enjoy some private time with Mamoru, she gets the feeling that someone is spying on them!  She's never fast enough to actually CATCH the spy, but she did catch a glimpse of the snoop's eyes!  Who was it this time?
</P>

<P align="center">
The eyes...<br>
<img src="images/snoop56.jpg" border=1>
</P>

<P>
<center>
<form action="games_snoop.php?answer" method="post">

<input type="text" name="character" size="20"><br>
<input type="submit" value="Guess!">
</form>

</center>
</P>

<P>
Last round's answer:<br>
<b>Prince Dimando</b><br>
<img src="images/snoop55.jpg" border=1>
</P>

<? /*-------------------------------------------------------*/ ?>

<? } elseif ($_SERVER['QUERY_STRING'] == "answer") {

$character1 = "osakanaru";

if ($_POST["character"]=="$character1") 
  { ?>

<h1>snoop!</h1>

<P>
Yes, it was <b>Osaka Naru</b> spying on the happy couple!  Take ONE card AND the playing card!
</P>

<P>
<center>
<?php
echo "<img src=/images/cards/" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $puzzle[array_rand($puzzle,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $puzzle[array_rand($puzzle,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=\"/" . $playing[array_rand($playing,1)] . $digits3[array_rand($digits3,1)] ."\">\n";
?>
</center>
</P>

  <? }
else {
  echo "<p>Sorry, but that was the wrong answer.  Please try again!</p>";
  } 
} 

include('/home/.lafayette/clavis/legend.neo-romance.net/bottom.php'); ?>

 

That was in the .txt file.... lol

Link to comment
Share on other sites

Rather than adding something onto the end of the URL, just give the submit button a value, and test to see if it is set:

 

<?php

include('/home/.lafayette/clavis/legend.neo-romance.net/top.php');
include('/home/.lafayette/clavis/legend.neo-romance.net/reward.php');

if(!isset($_POST['submit'])) { ?>

<h1>snoop!</h1>

<P align="center">
<img src="images/snoop00.jpg">
</P>

<P>
Every time Usagi is about to enjoy some private time with Mamoru, she gets the feeling that someone is spying on them!  She's never fast enough to actually CATCH the spy, but she did catch a glimpse of the snoop's eyes!  Who was it this time?
</P>

<P align="center">
The eyes...<br>
<img src="images/snoop56.jpg" border=1>
</P>

<P>
<center>
<form action="games_snoop.php" method="post">

<input type="text" name="character" size="20"><br>
<input type="submit" value="Guess!" name="submit">
</form>

</center>
</P>

<P>
Last round's answer:<br>
<b>Prince Dimando</b><br>
<img src="images/snoop55.jpg" border=1>
</P>

<? /*-------------------------------------------------------*/ ?>

<?php } else{//no need to use elseif and test the same condition again - it cant be both true and false

$character1 = "osakanaru";

if ($_POST["character"]=="$character1") 
  { ?>

<h1>snoop!</h1>

<P>
Yes, it was <b>Osaka Naru</b> spying on the happy couple!  Take ONE card AND the playing card!
</P>

<P>
<center>
<?php
echo "<img src=/images/cards/" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $regular[array_rand($regular,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $puzzle[array_rand($puzzle,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=/images/cards/" . $puzzle[array_rand($puzzle,1)] . $digits[array_rand($digits,1)] .">\n";
echo "<img src=\"/" . $playing[array_rand($playing,1)] . $digits3[array_rand($digits3,1)] ."\">\n";
?>
</center>
</P>

  <? }
else {
  echo "<p>Sorry, but that was the wrong answer.  Please try again!</p>";
  } 
} 

include('/home/.lafayette/clavis/legend.neo-romance.net/bottom.php'); ?>

Link to comment
Share on other sites

Hi GingerRobot,

 

Thanks for your help.  I still got an error, but then I realized that the problem all along was here!

 

<form action="games_snoop.php?answer" method="post">
<input type="text" name="character" size="20"><br>
<input type="submit" value="Guess!">
</form>

 

The OLD file was named "games_snoop.php" to help me sort all the files that were lumped in my root directory for the subdomain.  The new file was simply "snoop.php" and I overlooked the place in the form where it needed to be corrected.

 

*headdesk*

 

But your POST solution is much nicer than what we were using before, so I'll be fixing up the rest of the files to take advantage of that.  Thanks again!

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.