Grr Sometimes My Code Works... Sometimes It Doesn't


#1

I need help with a code that appears to pass an empty variable


#2

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.
  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).

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]

<?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'; ?>

[/php]

Airlinecodesask.php
[php]


<?php

include(“airlinecodes.php”);
$choice=rand(0,sizeOf($codes)-1);

$code=$codes[$choice];
$airline=$airlines[$choice];

print("What is the code for $airline?<p>n");
print("<form action='airlinecodescheck.php' method='post'>");
print("<input type='text' name='code' size='20'><p>n");
print("<input type='hidden' name='choice' value=$choice><p>n");
print("<input type='submit' value='Submit Answer'>");
print("</form>n");

?>

[/php]

Airlinecodescheck.php
[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");
}

?>

[/php]

Answerairlinecodes.php
[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");

?>

[/php]

Admin Edit: Added PHP code tags for readability. Please see http://phphelp.com/guidlelines.php for posting guidelines.