kiro 0 Report post Posted March 31, 2005 Here's the guessing script, they guess a number and checks if they are right or wrong.. <form method="guess.php?action=yes"><input type="text" name="t_guess"><br><input type="submit" value="Guess"><?phpif($action==yes){//have the number that they are suppose to guess...$guess=14;//endif($t_guess==$guess){print "Good job! Guess was right!";}else{print "Guess was wrong! Try again!";}}?> Thats it Share this post Link to post Share on other sites
spacemonkey 0 Report post Posted March 31, 2005 Here's the guessing script, they guess a number and checks if they are right or wrong.. <form method="guess.php?action=yes"><input type="text" name="t_guess"><br><input type="submit" value="Guess"><?phpif($action==yes){//have the number that they are suppose to guess...$guess=14;//endif($t_guess==$guess){print "Good job! Guess was right!";}else{print "Guess was wrong! Try again!";}}?>Thats it 66435[/snapback] Well, that is a nice little script. I can see this being useful for people new to PHP and the like. Although this is a very simple script and it is not intended to be too complicated for beginners, I will go ahead and say that this could be a valuable resource to have, just for reference. Share this post Link to post Share on other sites
Carsten 0 Report post Posted April 2, 2005 If you really want to guess a number, you should use php's rand() function. Look at http://de1.php.net/rand for more information. For example, if you want someone to guess a random number between 1 and 20, replace $guess=14; with $guess=rand(1,20);. The new script would be: <form action="guess.php?action=yes" method="post"><input type="text" name="t_guess"><br><input type="submit" value="Guess"><?phpif($action == "yes"){//have the number that they are suppose to guess...$guess=rand(1,20);//endif($_POST['t_guess'] == $guess){print "Good job! Guess was right!";}else{print "Guess was wrong! Try again!";}}?>Note that I have made some replacements. method="guess.php?action=yes"with action="guess.php?action=yes" method="post"because method can only be post and action, and the target has to be set with action. I also replacedif($action == yes){with if($action == "yes"){because your code would return an error without single our double quotes. I also replacedif($t_guess == $guess){with if($_POST['t_guess'] == $guess){because now it checks for a post argument and arguments posted via the url, get arguments, aren't valid as input. Share this post Link to post Share on other sites
kiro 0 Report post Posted April 3, 2005 Sorry for the mistakes guys.. thanks for the updates Carsten.. Share this post Link to post Share on other sites
GMTech 0 Report post Posted April 3, 2005 Hmm, that's nice, not too advance, I don't see much practicality, but it's a good tutorial for some basic php though. Share this post Link to post Share on other sites