scriptham Posted December 26, 2007 Share Posted December 26, 2007 Hi I am struggling to get the following script to work. As you can probably guess it is from a book. I am working towards a modest website and this is my starting point. The basic idea is that the user guesses the num_to_guess entering their guess in the html form and submitting it. The php then checks it against the preset value and displays a higher, direct hit or lower type message. When run the form appears but in use the message does not change, can anyone spot the error please. I am using the Abyss webserver in winXP it is set up to run php and some basic php has already worked so I believe the set up is correct. <?php $num_to_guess = 42; if (!isset($_Post[guess])) { $message= "Welcome to the guessing machine"; } else if ($_Post[guess] > $_num_to_guess) { $message= "$_Post[guess] is too large. Try a smaller number."; } else if ($_Post[guess] < $_num_to_guess) { $message= "$_Post[guess] is too small. Try a larger number."; } else { $message= "Well Done"; } //unset ($_Post[guess]); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Page title</title> </head> <body> <form action="<?php echo $_SERVER[php_SELF] ?>" method="POST"> <p>Type your guess here: <input type="text" name="guess"/></p> <p><input type="submit" value="submit your guess"/></p> </form> <?php <h1> echo $message </h1> ?> </body> </html> I look forward to hearing from you. Many thanks ScriptHam Quote Link to comment https://forums.phpfreaks.com/topic/83233-solved-simple-xp-form-fault/ Share on other sites More sharing options...
jitesh Posted December 26, 2007 Share Posted December 26, 2007 <?php $num_to_guess = 42; if (!isset($_POST['guess']) or empty($_POST['guess'])){ $message= "Welcome to the guessing machine"; }else if ($_POST['guess'] > $num_to_guess){ $message= $_POST['guess'] ." is too large. Try a smaller number."; }else if ($_POST[guess] < $num_to_guess){ $message= $_POST['guess'] ." is too small. Try a larger number."; }else{ $message= "Well Done"; } //unset ($_Post[guess]); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Page title</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <p>Type your guess here: <input type="text" name="guess"/></p> <p><input type="submit" value="submit your guess"/></p> </form> <?php echo "<h1>"; echo $message; echo "</h1>"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/83233-solved-simple-xp-form-fault/#findComment-423401 Share on other sites More sharing options...
graham23s Posted December 26, 2007 Share Posted December 26, 2007 yep always capitalise your: $_POST as it's a superglobal more information here for ya: http://uk.php.net/variables.predefined Graham Quote Link to comment https://forums.phpfreaks.com/topic/83233-solved-simple-xp-form-fault/#findComment-423403 Share on other sites More sharing options...
scriptham Posted December 26, 2007 Author Share Posted December 26, 2007 Hi Thanks jitesh, thanks Graham. Bang on the money of course. Again many thanks ScriptHam Quote Link to comment https://forums.phpfreaks.com/topic/83233-solved-simple-xp-form-fault/#findComment-423417 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.