webdevdea Posted March 14, 2014 Share Posted March 14, 2014 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 More sharing options...
requinix Posted March 14, 2014 Share Posted March 14, 2014 }elseif($guess = $number) {One equals sign is for assignment, two equals signs are for comparison. Link to comment https://forums.phpfreaks.com/topic/286954-help-with-guess-number-game/#findComment-1472532 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.