vedder Posted January 20, 2012 Share Posted January 20, 2012 Hi guys! First of all I'd like to thank you for reading my question. I think it's a basic one indeed! I've started to learn php and wanted to code a small game in html + php. The principle is basic: I generate two random numbers between 1 and 10, $a and $b. I keep its sum in $result=$a+$b I echo them to the screen and ask the user to input their sum in an html form input field with a submit button. When I receive the value from the html form I want to compare if the user input is equal to the sum of the two numbers presented. What happens is that when I hit the submit button the browser reads all the code again and generates two new numbers $a and $b and I cannot compare if what the user inputted is true or not because the browser reads all the file. My question is how can I control the flow of the program to avoid it. Any tips for a newby like me? Quote Link to comment https://forums.phpfreaks.com/topic/255447-php-and-html-flow-control/ Share on other sites More sharing options...
Proletarian Posted January 21, 2012 Share Posted January 21, 2012 You're going to have to save your random variables on the server in a file or in a database and recall them when the user input is sent back for comparison. Quote Link to comment https://forums.phpfreaks.com/topic/255447-php-and-html-flow-control/#findComment-1309703 Share on other sites More sharing options...
vedder Posted January 23, 2012 Author Share Posted January 23, 2012 That's what I thought. Thank you very much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/255447-php-and-html-flow-control/#findComment-1310378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.