Guess the number script error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Guess the number script error

    I'm new to php and i'm trying to code guess the number script without MySQL now my problem is the loop runs forever, the DEMO HERE and the php code looks like
    PHP Code:
    <?php
        
    print    '<html>
                <head>
                    <title>KONVICT.mobi | online games | Guess the number</title>
                    <link rel=\'stylesheet\' href=\'./style.css\' type=\'text/css\'/>
                </head>
            <body><img src=\'./logo.png\' alt=\'GTN\'/><br>
             This page should allow to play GTN game<br><br>
             Enter your guess between zero and 30'
    ;
    //Generate a random number between zero and 30
             
    $num    =    rand(0,30);
    //Accept and post input from user
             
    $input    =    print '<form action=\'GTN.php\' method=\'POST\'>
                           <input type=\'text\' name=\'input\' size=\'2\'><br>
                           <input class=\'buttom\' type=\'submit\' value=\'Guess\'>
                           </form>'
    ;
             
    $guess    =    $_POST["input"];
             if(
    $guess==$num)
             print 
    'You are correct! the number is'.$num.'!';
    //If input incorrect allow user to try again
             
    while($num!=$guess)
             {
             if(
    $guess<$num)
             {
             print 
    'Guess low try again :';
             
    $input    =    print '<form action=\'GTN.php\' method=\'POST\'>
                           <input type=\'text\' name=\'input\' size=\'2\'><br>
                           <input class=\'buttom\' type=\'submit\' value=\'Guess\'>
                           </form>'
    ;
            }
            else
            {
            print    
    'Guess high, try again :';
            
    $input    =    print '<form action=\'GTN.php\' method=\'POST\'>
                           <input type=\'text\' name=\'input\' size=\'2\'><br>
                           <input class=\'buttom\' type=\'submit\' value=\'Guess\'>
                           </form>'
    ;
             }
             
             }
             
             
        
        print 
    '</body>
                </html>'
    ;
        
        
        
        
    ?>
    libra.wen.ru

    #2
    remove this from your script: while($num!=$guess) { } it does not make any sense.
    Advertise your mobile site for FREE with AdTwirl

    Comment


      #3
      Thank you bro, i am getting another error but i will try to fix it, if i can't i will post here again but the loop problem is solved
      libra.wen.ru

      Comment

      Working...
      X