My GTN php game is showing a blank page

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

    My GTN php game is showing a blank page

    Hey guys i'm upgrading guess the number game i created, i saved the number on a text file but i had problems if many users played the game simultaneously because the number gets overwritten so now i want to use a database to store the number where a nickname, ip address, generated number and user id will be stored. But now the game shows blank pages can you help? Here's the source code
    PHP Code:
    <html>
    <head>
    <title>wapEvening | Guess the number game</title>
    <link rel="stylesheet" type="text/css" href="includes/style.css"/>
    </head>
    <body>
    <?php
    require_once "includes/header.inc";
    require_once 
    "includes/con.inc";
    $ran rand(1,50);
    $ip  $_SERVER['HTTP_X_FORWARDED_FOR'];
    $insert "INSERT INTO *** (id,ip,number)
    VALUES(NULL,
    {$ip},{$ran})";
    $enter = @mysql_clean(mysql_query($insert));
    print 
    'Welcome to guess the number game, you have 5 chances to guess the number between 1 and 50
    (included) you loose 10 points for every incorrect number you guess, you get a bonus of 20
    points if you guess correct number first time'
    ;
    $nick  = print '<input type="text" size="5" maxlength="10" name="nick">';
    $guess = print '<input type="text" size="1" maxlength="1" name="guess">';
    print 
    "\nEnter :\n<form action=\"gtn_answer.php\" method=\"POST\">Nickname : ".$nick."\nYour
    guess : "
    .$guess."</form>";
    ?>
    </body>
    </html>
    libra.wen.ru

    #2
    You have a fatal error on $enter = @mysql_clean(mysql_query($insert)); -> remove @ to see what is the problem ....
    Better use Sessions instead database for a little game ...
    <?php unlink('World/Europe/Romania.country'); ?>

    Comment


      #3
      For example:
      PHP Code:
      function mysql_clean($var) {
      $var mysql_real_escape_string($var);
      return 
      $var;

      <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

      Comment


        #4
        You cant clean the query ....
        and here its a simple example ...

        PHP Code:
        <?php
        // author : Ionutxp
        // of course , whatever

        session_start();
        error_reporting(0);

        if (isset(
        $_GET['action']))
            
        $act $_GET['action'];
        else
            
        $act '';

        function 
        check_game()
        {
            if (!isset(
        $_SESSION['game_number']))
            {
                return 
        'INACTIVE';
            }
            if (isset(
        $_SESSION['game_number']) && $_SESSION['game_errors'] < && !$_SESSION['game_guessed'])
            {
                return 
        'ACTIVE';
            }
            if (isset(
        $_SESSION['game_guessed']) && $_SESSION['game_guessed'])
            {
                return 
        'WON';
            }
            if (isset(
        $_SESSION['game_errors']) && $_SESSION['game_errors'] > 4)
            {
                return 
        'LOSE';
            }
            
        print_r($_SESSION);
        }
        function 
        print_formular($params = array('status' => 1'text' =>'Type a number!'))
        {
        ?>
         <html> 
        <head> 
        <title>wapEvening | Guess the number game</title> 
        <link rel="stylesheet" type="text/css" href="includes/style.css"/> 
        </head> 
        <body>System: 
        <?php print $params['text']?>
        <br/>
        <?php if ($params['status'] != 2)
        {
        ?>
        <form action="" method="post">
        Number : <input type="text" name="number"/>
        <input type="submit" value="Try!"/>
        </form>
        <?php
        }
        ?>
        </body> 
        </html>   
         <?php

        }

        if (isset(
        $_GET['newgame']))
        {
            unset(
        $_SESSION['game_number']);
            unset(
        $_SESSION['game_guessed']);
            unset(
        $_SESSION['game_errors']);
            
        header('Location: guess_number.php');
        }
        $arr = array();
        $game_status check_game();

        switch (
        $game_status)
        {
            case 
        'INACTIVE':
                {
                    
        $_SESSION['game_number'] = mt_rand(1100);
                    
        $_SESSION['game_guessed'] = false;
                    
        $_SESSION['game_errors'] = 0;
                    
        print_forumlar();
                }
                break;
            case 
        'ACTIVE':
                {
                    if (isset(
        $_POST['number']) && ((int)$_POST['number'] > && (int)$_POST['number'] <=100))
                    {
                        if (
        $_POST['number'] == $_SESSION['game_number'])
                        {
                            
        // give plusses sql
                            
                            
        $_SESSION['game_guessed'] = true;
                            
        $arr['text'] = 'You won!';
                            
        $arr['status'] = 2;
                            
        print_formular($arr);
                            exit;
                        }
                        if (
        $_POST['number'] != $_SESSION['game_number'])
                        {
                            
        // here you can put mysql query to extract plusses
                            
        $_SESSION['game_errors']++;
                            if (
        $_SESSION['game_errors'] < 5)
                            {
                                if (
        $_POST{'number'} > $_SESSION['game_number'])
                                {
                                    
        $arr['text'] = 'The secret number is lower.';
                                    
        $arr['status'] = 1;
                                }
                                else
                                {
                                    
        $arr['text'] = 'The secret number is bigger.';
                                    
        $arr['status'] = 1;
                                }
                                
        print_formular($arr);
                                exit;
                            }
                            else
                            {
                                
        // lose
                                
        $arr['text'] = 'You lose.';
                                
        $arr['status'] = 2;
                                
        print_formular($arr);
                                exit;
                            }
                        }
                    }
                    else
                        
        print_formular();
                    exit;
                }
                break;
            case 
        'WON':
                echo 
        'Already won! Start a new game?!<br/><a href="' $_SERVER['php_self'] .
                    
        '?newgame">YES!</a>';
                break;
            case 
        'LOSE':
                echo 
        'Already losed! Start a new game?<br/><a href="' $_SERVER['php_self'] .
                    
        '?newgame">YES!</a>';
                break;
        }
        ?>
        I didnt tested yet ...
        <?php unlink('World/Europe/Romania.country'); ?>

        Comment


          #5
          Thats just what "mysql_clean" in this case probably ment to be.
          <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

          Comment


            #6
            PHP Code:
            $nick  = print '<input type="text" size="5" maxlength="10" name="nick">'
            $guess = print '<input type="text" size="1" maxlength="1" name="guess">'
            to :
            PHP Code:
            $nick  =  '<input type="text" size="5" maxlength="10" name="nick">'
            $guess =  '<input type="text" size="1" maxlength="1" name="guess">'
            will help as there is no need to print thoose lines

            Comment


              #7
              Thanks guys i removed
              PHP Code:
              @mysql_clean 
              now the script is working
              and Thanks to
              Originally posted by something else View Post
              [PHP]
              PHP Code:
              $nick  =  '<input type="text" size="5" maxlength="10" name="nick">'
              $guess =  '<input type="text" size="1" maxlength="1" name="guess">'
              will help as there is no need to print thoose lines
              That's a stupid mistake i made there
              libra.wen.ru

              Comment

              Working...
              X