Results 1 to 10 of 17

Thread: Day 9 - Lets Make A Game - Part 2 - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

    http://php.flashwebhost.com/stefin/games_10.php

    Code:
    <html>
    <body>
    <h1>Number Guessing Game.</h1>
    
    <?php
    
    if (isset($_POST['secretNumber'])) {
    $secretNumber = $_POST['secretNumber'];
    } else {
     $secretNumber = rand(1,500);
    }
    if (isset($_POST['userNumber'])) {
    $userNumber = $_POST['userNumber'];
    if ($secretNumber > $userNumber) {
    echo '<h1 style="color:BLACK">Think Greater.</h1>';
    } else if ($secretNumber < $userNumber) {
    echo '<h1 style="color:GREEN">Think Smaller.</h1>';
    } else {
    echo '<h1 style="color:RED">Good Job, You win the game.</h1>';
    }
    }
    ?>
    
    <form method="POST" action="">
    Enter Number: <input name="userNumber" type="text">
    <button type="submit">Check</button>
    <input type="hidden" name="secretNumber" value="<?php echo $secretNumber; ?>">
    </form>

  2. #2
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by stefin View Post
    http://php.flashwebhost.com/stefin/games_10.php

    Code:
    <html>
    <body>
    <h1>Number Guessing Game.</h1>
    
    <?php
    
    if (isset($_POST['secretNumber'])) {
    $secretNumber = $_POST['secretNumber'];
    } else {
     $secretNumber = rand(1,500);
    }
    if (isset($_POST['userNumber'])) {
    $userNumber = $_POST['userNumber'];
    if ($secretNumber > $userNumber) {
    echo '<h1 style="color:BLACK">Think Greater.</h1>';
    } else if ($secretNumber < $userNumber) {
    echo '<h1 style="color:GREEN">Think Smaller.</h1>';
    } else {
    echo '<h1 style="color:RED">Good Job, You win the game.</h1>';
    }
    }
    ?>
    
    <form method="POST" action="">
    Enter Number: <input name="userNumber" type="text">
    <button type="submit">Check</button>
    <input type="hidden" name="secretNumber" value="<?php echo $secretNumber; ?>">
    </form>
    Good script.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •