Passing Variables without forms
Posted: Sat Dec 02, 2006 5:27 pm
Im not sure if the pseudo code shows clearly what im trying to do but ill try to explain it too
When the page is first loaded it generates a form and a random number. Then when the user enters something in the form and submits it, it refreshes the page, and even if the user entered the correct random number first displayed, it returns "User entered the incorrect number" because $randomNumber is null. I know I could obviousally pass the randomNumber through a hidden form field, but that would kind of defeat the whole porpose of my script. I am also aware I could just store the value in a database/text file but I dont want to do that either. Im wondering if it is possable to accomplish this using functions or arrays or something...
Code: Select all
<?php
if(!isset($_GET['answer'])){
$randomNumber = rand(0,10);
echo "Enter the value you see: <br><form id='validation' name='validation' method='get' action='test2.php'>
<input type='text' name='answer' />
<input type='submit' />
</form>";
echo "<br>Random Number = " . $randomNumber . "<br>";
} else {
if($_GET['answer'] == $randomNumber){
echo "User entered the correct number.";
//echo "<br>Random Number = " . $randomNumber . "<br>";
} else {
echo "User entered the incorrect number";
//echo "<br>Random Number = " . $randomNumber . "<br>";
}
}
?>