Not passing variables or generating random numbers!

Hello Everyone,

For starters I have literally never posted on a messageboard ever so if violate any proper posting etiquette please let me know. I will not be offended. My problem though…

Ok, so on some computers my code for an airline-codes quiz works and on others (most importantly the one at work) it doesn’t. I have uploaded the site to http://www.zendurl.com/mradamla/index.html for anyone to test and see if they can figure out the problem. The main problems are as follows though:

  1. It repeats the same question. It almost appears like the random number generator (passed through the variable “$choice”) is sending the same number evertime and never making a new number when the page refreshes.

  2. It apparently does not pass the answers to the page after you click ‘submit answer’ so you get a “Correct! [absent variable] is the code for [absent variable]” message. (Please note: the [absent variable] is just a blank space on the page. For example it should say “Correct! CO is the code for Continental Airlines”).

The code works on my local server setup (127.0.0.1) and on my computers at home as well as my cell phone. It doesn’t work at work though or on my friends cell phone.

I am going to put the code below here for everyone to look at so please excuse the length of the post. It is in four files basically (each of the four basic files were cloned and customized to each of the four quizzes you see on the page (Airport Codes Quiz, Airport Cities Quiz, Airline Codes Quiz, Airline Names Quiz). I am only uploading the Airline Codes Quiz though since it is the shortest. Please let me know if the rest of the quiz codes could assist you in any way. Thanks.

Airlinecodes.php

<?php $airlines= Array(); $codes= Array(); $airlines[]='Aeromexico';$codes[]='AM'; $airlines[]='Air Canada';$codes[]='AC'; $airlines[]='Alaska Airlines';$codes[]='AS'; $airlines[]='Aloha Airlines';$codes[]='AQ'; $airlines[]='America West Airlines';$codes[]='HP'; $airlines[]='American Airlines';$codes[]='AA'; $airlines[]='CapeAir';$codes[]='9K'; $airlines[]='Colgan Air';$codes[]='9L'; $airlines[]='Commutair';$codes[]='C5'; $airlines[]='Continental Airlines';$codes[]='CO'; $airlines[]='Delta Airlines';$codes[]='DL'; $airlines[]='Gulfstream International Airlines';$codes[]='3M'; $airlines[]='Hawaiian Airlines';$codes[]='HA'; $airlines[]='Island Air';$codes[]='WP'; $airlines[]='Mexicana';$codes[]='MX'; $airlines[]='Northwest Airlines';$codes[]='NW'; $airlines[]='RegionsAir';$codes[]='3C'; $airlines[]='Southwest Airlines';$codes[]='WN'; $airlines[]='United Airlines';$codes[]='UA'; $airlines[]='US Airways';$codes[]='US'; [u]Airlinecodesask.php[/u]
<?php include("airlinecodes.php"); $choice=rand(0,sizeOf($codes)-1); $code=$codes[$choice]; $airline=$airlines[$choice]; print("What is the code for $airline?

n"); print(""); print("

n"); print("

n"); print(""); print("n"); ?>

Airlinecodescheck.php


<?php include('airlinecodes.php'); $correctcode=$codes[$choice]; $correctcode2=$codes[$choice]; $correctairlines=$airlines[$choice];
if ($code=strtoupper($code) == $correctcode2=strtoupper($correctcode))
{
print("Correct! $correctcode is the code for $correctairlines!");
print("<p><a href='airlinecodesask.php'>");
print("Next Question </a>");
print("<br><br>Or, <a href='index.html'>Return To Main Options");
}

else
{
print("Wrong! try again:<p>n");
print("What is the code for $correctairlines?<br>");
print("<form action='airlinecodescheck.php' method='post'>n");
print("<input type='text' name='code'><br>n");
print("<input type='hidden' name='choice' value=$choice>n");
print("<input type='submit' value='Submit Answer'>");
print("</form>n");
print("<a href='airlinecodesask.php'>");
print("Next Question </a><p>n");

print("<form action='answerairlinecodes.php' method='post'>n");
print("<input type='hidden' name='choice' value=$choice>n");
print("<input type='submit' value='Show Answer'>");
print("</form>n");
}

?>

Answerairlinecodes.php


<?php include('airlinecodes.php'); $correctcode=$codes[$choice]; $correctcode2=$codes[$choice]; $correctairline=$airlines[$choice];
print("$correctcode is the code for $correctairline!");
print("<p><a href='airlinecodesask.php'>");
print("Next Question </a>");
print("<br><br>Or, <a href='index.html'>Return To Main Options");

?>

Please do not double post.

If you are not getting any replies, try and restate the question to clarify it. Also consider limiting the amount of code you post to what you believe is the ESSENTIAL information not all possible code…

Please also pay attention to posting guidelines particularly in the area of formatting using the phpBB code tags and the enhanced PHP tag that is available in this forum. More information on this can be found at http://phphelp.com/guidelines.php.

To reply to this topic, please refer to the original post at http://phphelp.com/forums/viewtopic.php?p=27382 as this topic is now locked.

Sponsor our Newsletter | Privacy Policy | Terms of Service