Jump to content

[SOLVED] Simple XP form fault


scriptham

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/83233-solved-simple-xp-form-fault/
Share on other sites

<?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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.