Jump to content

Help with Guess number game


Go to solution Solved by requinix,

Recommended Posts

I have my code almost working, I am still new with this so if someone could help me understand why this thing is letting you know you win if you choose anything between 20 and 25?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Computer can you guess my number</title>
<style type = "text/css">

#footer {font-size:xx-small;
         text-align:center;
	 clear:right;
         padding-bottom:20px;
}
body { 
background-image:url("img_tree.png");
 color: RED;text-align:center  }
p {  color: Blue; text-align:center;}
</style>
</head>
<body>


<?php
$guess=$_POST['guess'];
$number= 25;

if($guess>$number) {
echo "Sorry, your guess is too high, try again";
echo "<form method=\"post\" name=\"guess\">
<input type=\"hidden\" name=\"number\" value=\"$number\">
Pick a number 1 through 25: <input name=\"guess\" type=\"text\">
<input name=\"submit\" type=\"submit\" value=\"Submit Guess\">
</form>";
}elseif($guess <15){
echo "Sorry, your guess is too low, try again";
echo "<form method=\"post\" name=\"guess\">
<input type=\"hidden\" name=\"number\" value=\"$number\">
Pick a number 1 through 25: <input name=\"guess\" type=\"text\">
<input name=\"submit\" type=\"submit\" value=\"Submit Guess\">
</form>";
}elseif($guess = $number) {
echo "You got it, good guess";
echo "You got it, good guess.";

$number= 25;
echo "<form method=\"post\" name=\"guess\">
<input type=\"hidden\" name=\"number\" value=\"$number\">
Pick a number 1 through 25: <input name=\"guess\" type=\"text\">
<input name=\"submit\" type=\"submit\" value=\"Submit Guess\">
</form>";
}
else{

?><form method="post" name="guess">
<input type="hidden" name="number" value="<?php echo $number; ?>">
Pick a number 1 through 25: <input name="guess" type="text">
<input name="submit" type="submit" value="Submit Guess">
</form>
<?php } ?>


</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/286954-help-with-guess-number-game/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.