eugeniu Posted July 13, 2008 Share Posted July 13, 2008 I recently made a script that shows a picture selected from a text database, and has the person input what it says. On the next page it should say "Correct!" or "Incorrect..." and a comment on the specific image based on the previous image. This is what I have right now: <?php //Set the database filename $db = "words.txt"; //Read the file and store the lines in an array $lines = file($db); //Count the lines in the array $lc = count($lines) - 1; //echo $lc; //Select a random line $rl = rand(0, $lc); //echo "\n" . $rl; //Separate the items on the chosen line $sep = explode(":", $lines[$rl]); $trans = strtolower($sep[0]); //English pronunciation (lower case) //echo "\n" . $trans; $desc = $sep[1]; //Description of word //echo "\n" . $desc; include ("header.php"); include ("header2.php"); if (isset($_POST['submit'])) { $answer = strtolower($_POST['answer']); if ($answer == $trans) { echo "<br><b><font color=\"#28ab00\" size=\"1\" face=\"Verdana\">Correct! </b><font color=\"000000\">"; echo $desc; echo "<br></font>"; } else { echo "<br><b><font color=\"#c00000\" size=\"1\" face=\"Verdana\">Incorrect... </b><font color=\"000000\">"; echo $desc; echo "<br></font>"; } } echo "<img src=\"words/" . $trans . ".png\"><br> <form id=\"quiz\" action=\"words.php\" method=\"post\"> <input type=\"text\" name=\"answer\" size=\"8\" maxlength=\"30\"> <input type=\"submit\" name=\"submit\" value=\">>\"> </form><br><a href=\"http://kanaquest.com/main.php\">Home</a> | <a href=\"instructions.php\">Instructions</a>"; include ("footer2.php"); include ("footer.php"); ?> But sadly, the script determines if you are correct based on the next image. So if the first page has picture "A" and you enter "A", but on the next page, the picture is picture "B" then the script compares answer "A" with picture "B". Which is useless. How can I rewrite this so it compares the given answer with the right image? Link to comment https://forums.phpfreaks.com/topic/114540-solved-my-script-is-useless-unless-youre-a-fortune-teller-or-time-lord/ Share on other sites More sharing options...
AndyB Posted July 13, 2008 Share Posted July 13, 2008 save the image info in a session as soon as it's selected. retrieve the session value when you do the comparison. OR place the image info in a hidden field of your form and retrieve the passed info on the next page. Link to comment https://forums.phpfreaks.com/topic/114540-solved-my-script-is-useless-unless-youre-a-fortune-teller-or-time-lord/#findComment-589004 Share on other sites More sharing options...
eugeniu Posted July 13, 2008 Author Share Posted July 13, 2008 How exactly do I do that. ??? Link to comment https://forums.phpfreaks.com/topic/114540-solved-my-script-is-useless-unless-youre-a-fortune-teller-or-time-lord/#findComment-589005 Share on other sites More sharing options...
eugeniu Posted July 13, 2008 Author Share Posted July 13, 2008 NVM, I found a tutorial for sessions and it works properly now! Thanks! Link to comment https://forums.phpfreaks.com/topic/114540-solved-my-script-is-useless-unless-youre-a-fortune-teller-or-time-lord/#findComment-589022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.