Well there were a few things wrong with your code...
1) You forgot to include a '?' on your form action. That's why you were getting a 404 error.
2) You should use $_POST['guess'] since you're getting the value from an html form...
I made a few adjustments to your code. It should work now...
<?php
$num_to_guess = 42;
$message="";
if (!isset($_POST['guess']))
{
$message="Welcome to the guessing machine!";
}
elseif ($_POST['guess'] > $num_to_guess)
{
$message = "$guess is too big! Try a smaller number";
}
elseif ($_POST['guess'] < $num_to_guess)
{
$message = "$guess is too big! Try a bigger number";
}
else // ($guess == $num_to_guess)
{
$message = "Holy cow! You guessed it right";
}
?>
<html>
<head>
<title>on same page PHP script</title>
</head>
<body>
<h1>
<?php print $message ?>
</h1>
<form action = "<?php print $PHP_SELF?>" method="POST">
Type your guess here: <input type="text" name="guess">
<input type="submit" value"hit it!">
</form>
</body>
</html>